View previous topic :: View next topic |
Author |
Message |
richardd
Joined: 14 Oct 2008 Posts: 11
|
Posted: Wed Oct 15, 2008 10:52 pm Post subject: Always get "Access Denied" when attempting to chan |
|
|
Hi all,
I have a routine to change the password on Scheduled Tasks.
Seems to have a problem on Vista.
function TMainForm.ChangeTaskPasswords(const AComputerName, AUserName, APassword: String): Boolean;
// NOTE: Unlike with Services, which uses .\account for local accounts, Scheduled Tasks seem to use
// computername\account.
var
TaskScheduler: TTaskScheduler;
Index: Integer;
LogEntry: String;
ErrorMessage: String;
begin
Result := True;
try
TaskScheduler := TTaskScheduler.Create( nil );
try
TaskScheduler.AutoRefresh := False;
TaskScheduler.Duplicate := tdError;
TaskScheduler.Active := True;
TaskScheduler.TargetComputer := '\\' + AComputerName;
TaskScheduler.UseTaskScheduler1Only := True;
TaskScheduler.Refresh;
for Index := 0 to TaskScheduler.Count - 1 do begin
// Apparently the following call lets us access task properties:
try
TaskScheduler.Items[ Index ].Activate;
if AnsiSameText( TaskScheduler.Items[ Index ].AccountName, AComputerName + '\' + AUserName ) then
begin
// Log the action
LogEntry := Format( 'Changing Password for Task: %0:s', [ TaskScheduler.Items[ Index ].Name ] );
LogAndAddProgress( LogEntry );
TaskScheduler.Items[ Index ].SetAccountInformation( TaskScheduler.TargetComputer {AComputerName} + '\' + AUserName, APassword );
TaskScheduler.Items[ Index ].Save; // when I get here, I always get the error "Access Denied" (I do have the proper remote firewall settings on the Vista machine I am trying to change)
// Log the success
LogEntry := Format( 'Task Password Change (Success) | Task: %0:s',
[ TaskScheduler.Items[ Index ].Name ]);
LogAndAddProgress( LogEntry );
end;
except
on E: Exception do begin
// Log the failure
ErrorMessage := SysErrorMessage( GetLastError );
LogEntry := Format( 'Task Password Change (Failed) | Task: %0:s | Error: %1:s',
[ TaskScheduler.Items[ Index ].Name, ErrorMessage ]);
LogAndAddProgress( LogEntry );
end;
end;
end;
finally
TaskScheduler.Free;
end;
except
Result := False;
end;
end;
Any thoughts/suggestions? |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Thu Oct 16, 2008 10:44 am Post subject: |
|
|
Hi,
Please try to set
Code: | TaskScheduler.UseTaskScheduler1Only := True; |
before setting
Code: | TaskScheduler.Active := True;
TaskScheduler.TargetComputer := '\\' + AComputerName; |
|
|
Back to top |
|
 |
richardd
Joined: 14 Oct 2008 Posts: 11
|
Posted: Thu Oct 16, 2008 4:54 pm Post subject: Still get Access Denied error |
|
|
Thanks for the tips, but unfortunately, it did not solve the issue.
I still get the "Access Denied" error.
It works great when running from an XP machine to an XP machine but doesn't work from XP to Vista.
As anybody ever got this to work?
If so, got any code snippet to demonstrate?
Thanks in advance. |
|
Back to top |
|
 |
richardd
Joined: 14 Oct 2008 Posts: 11
|
Posted: Thu Oct 16, 2008 8:23 pm Post subject: Get same error message with Demo |
|
|
More findings:
I tried creating a new task on a remote Vista machine using the demo and I get the same error message (Access Denied).
I know I have firewall settings correct (Remote Task Management, etc) but still get that error on remote Vista machine (the app is running on XP).
I notice in a few places that the code path changes depending on if the current machine is on XP or Vista and above. Shouldn't we check the version of the remote computer not the machine where we run the app from?
Need help on this please. |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Fri Oct 17, 2008 2:40 am Post subject: |
|
|
Do you have Administrator access rights for Vista PC when you connect to it? |
|
Back to top |
|
 |
richardd
Joined: 14 Oct 2008 Posts: 11
|
Posted: Fri Oct 17, 2008 5:27 pm Post subject: |
|
|
Yes I am an administrator on the remote Vista machine. |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Mon Oct 20, 2008 5:23 am Post subject: |
|
|
From MSDN:
Quote: | For a Windows Server 2003, Windows XP, or Windows 2000 computer to create, monitor, or control tasks on a Windows Vista computer, the following operations should be completed on the Windows Vista computer, and the user who is calling the SetTargetComputer method must be a member of the Administrators group on the remote Windows Vista computer.
Enable the "Share File and Printers" exception in Windows Firewall
Click Start, and then click Control Panel.
In Control Panel, click Classic View and then double-click the Windows Firewall icon.
In the Windows Firewall window, click the Exceptions tab and select File and Printer Sharing exception check box.
Enable the "Remote Registry" service
Open a Command Prompt window and enter the following command: net start "Remote Registry" |
Did you setup Remote Registry as well? |
|
Back to top |
|
 |
|