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?
Always get "Access Denied" when attempting to chan
Hi,
Please try to set
before setting
Please try to set
Code: Select all
TaskScheduler.UseTaskScheduler1Only := True;
Code: Select all
TaskScheduler.Active := True;
TaskScheduler.TargetComputer := '\\' + AComputerName;
Best regards,
Igor Siticov.
Igor Siticov.
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.
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.
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.
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.
From MSDN:
Did you setup Remote Registry as well?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"
Best regards,
Igor Siticov.
Igor Siticov.