Always get "Access Denied" when attempting to chan

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Always get "Access Denied" when attempting to chan

Post by richardd »

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?
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hi,

Please try to set

Code: Select all

TaskScheduler.UseTaskScheduler1Only := True; 
before setting

Code: Select all

TaskScheduler.Active := True; 
TaskScheduler.TargetComputer := '\\' + AComputerName; 
Best regards,
Igor Siticov.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Still get Access Denied error

Post by richardd »

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.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Get same error message with Demo

Post by richardd »

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.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Do you have Administrator access rights for Vista PC when you connect to it?
Best regards,
Igor Siticov.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

Yes I am an administrator on the remote Vista machine.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

From MSDN:
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?
Best regards,
Igor Siticov.
Post Reply