Cannot run task scheduler under non-admin accounts.
Cannot run task scheduler under non-admin accounts.
Hi
My program creates tasks dynamically using TTaskScheduler.
The Problem :
The program executes fine under a computer administrator account and creates the tasks, but if i login and run the program under a non-admin user (or called a limited user ) the tasks do not get scheduler and return an error 'the task scheduler service is not running'. This error is created when one calls the create method for TTaskScheduler.
The Task Schedular service is running and one can manual add a task using the microsofts task scheduler wizard under a non-admin account.
Thanks.
My program creates tasks dynamically using TTaskScheduler.
The Problem :
The program executes fine under a computer administrator account and creates the tasks, but if i login and run the program under a non-admin user (or called a limited user ) the tasks do not get scheduler and return an error 'the task scheduler service is not running'. This error is created when one calls the create method for TTaskScheduler.
The Task Schedular service is running and one can manual add a task using the microsofts task scheduler wizard under a non-admin account.
Thanks.
Please check the following:
1) TTaskScheduler.Open is called after application startup
2) Task Scheduler Service is running in Automatic mode. This service could be started only by System and Power Users. To check its mode open Control Panel - Administrative Tools - Services and in the services list check the startup mode for Task Scheduler Service.
1) TTaskScheduler.Open is called after application startup
2) Task Scheduler Service is running in Automatic mode. This service could be started only by System and Power Users. To check its mode open Control Panel - Administrative Tools - Services and in the services list check the startup mode for Task Scheduler Service.
HI
This is a what i am doing - a summary version
procedure TfrmMain.Button1Click(Sender: TObject);
var
TaskScheduler: TTaskScheduler;
begin
TaskScheduler := TTaskScheduler.Create(nil);
TaskScheduler.Open;
showmessage('done');
TaskScheduler.close;
TaskScheduler.Destroy;
end;
It never gets to the showmessage.
The Task Scheduler Service is running and in Automatic mode and is started, the service is started by the local system account.
This is a what i am doing - a summary version
procedure TfrmMain.Button1Click(Sender: TObject);
var
TaskScheduler: TTaskScheduler;
begin
TaskScheduler := TTaskScheduler.Create(nil);
TaskScheduler.Open;
showmessage('done');
TaskScheduler.close;
TaskScheduler.Destroy;
end;
It never gets to the showmessage.
The Task Scheduler Service is running and in Automatic mode and is started, the service is started by the local system account.
Could you please specify what OS do you use?
Unfortunately, we were unable to reproduce your situation.
Could you please try the following code:
Unfortunately, we were unable to reproduce your situation.
Could you please try the following code:
Code: Select all
procedure TfrmMain.Button1Click(Sender: TObject);
var
TaskScheduler: TTaskScheduler;
begin
TaskScheduler := TTaskScheduler.Create(nil);
if TaskScheduler.StartScheduler then
ShowMessage('Scheduler started!')
else
ShowMessage('Scheduler failed to start!');
TaskScheduler.Open;
showmessage('Opened!');
TaskScheduler.Close;
TaskScheduler.Desctroy;
end;
Hi
I have tested the supplied code.
It works fine with a account with admin rights(I get both showmessages) but when logged on as a non-admin user it does not even get to showmessage and bombs at startscheduler.
I am using window XP pro Version 2002 service pack 1 - and has the latest updates from microsofts windows update site.
I created the non-admin(limited) user using the 'User accounts' applet in the 'control panel.
Thanks.
I have tested the supplied code.
It works fine with a account with admin rights(I get both showmessages) but when logged on as a non-admin user it does not even get to showmessage and bombs at startscheduler.
I am using window XP pro Version 2002 service pack 1 - and has the latest updates from microsofts windows update site.
I created the non-admin(limited) user using the 'User accounts' applet in the 'control panel.
Thanks.
I'm having this same problem, but only when compiled under Delphi 7. The Delphi 2005 compiled version works under a non-admin account, but has a different problem (won't let me clear the tfRunOnlyWhenLoggedOn flag, see my other post) and at any rate our production app is currently written under Delphi 7 so we need this version to work.
When I run the Demo application compiled with Delphi 7 under a straight Users member account, I get an immediate Windows fatal application error box and then a message dialog after I close that indicating that the Task Scheduler service is not running, even though the service is most definitely running. If I attempt to open the Demo project in Delphi 7 when running as this non-admin user, I get an error opening the main form that the Task Scheduler service is not running and the SI Components are removed from the form.
When I run the Demo application compiled with Delphi 7 under a straight Users member account, I get an immediate Windows fatal application error box and then a message dialog after I close that indicating that the Task Scheduler service is not running, even though the service is most definitely running. If I attempt to open the Demo project in Delphi 7 when running as this non-admin user, I get an error opening the main form that the Task Scheduler service is not running and the SI Components are removed from the form.
I had this bug as well, but fixed it by modifying the TTaskScheduler.StartScheduler function. I only modified the code for WinNT/2k/XP, making a change to how the rights for the service are obtained. For me, I was getting the same error message as everyone "Task Scheduler service not running", tracked it down to when we did TTaskScheduler.Open, which in turn calls StartScheduler(). Here is the code we modified, starting at the WinNT/2k/XP branch.
Code:
else
begin
hSC := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if hSC = 0 then
Result := GetLastError = 0
else
begin
// 1.0.4
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_QUERY_STATUS);
if hSchSvc = 0 then
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_START);
CloseServiceHandle(hSC);
if hSchSvc = 0 then
Result := GetLastError = 0
else
begin
if not QueryServiceStatus(hSchSvc, SvcStatus) then
begin
CloseServiceHandle(hSchSvc);
Result := GetLastError = 0;
end
else
begin
if SvcStatus.dwCurrentState = SERVICE_RUNNING then
begin
CloseServiceHandle(hSchSvc);
Result := True;
end
else
begin
ServiceArgVectors := nil;
//changed code here
CloseServiceHandle(hSchSvc);
hSC := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_START);
CloseServiceHandle(hSC);
if not StartService(hSchSvc, 0, ServiceArgVectors) then
begin
CloseServiceHandle(hSchSvc);
Result := GetLastError = 0;
end
else
begin
CloseServiceHandle(hSchSvc);
Result := True;
end;
end;
end;
end;
end;
Code:
else
begin
hSC := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if hSC = 0 then
Result := GetLastError = 0
else
begin
// 1.0.4
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_QUERY_STATUS);
if hSchSvc = 0 then
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_START);
CloseServiceHandle(hSC);
if hSchSvc = 0 then
Result := GetLastError = 0
else
begin
if not QueryServiceStatus(hSchSvc, SvcStatus) then
begin
CloseServiceHandle(hSchSvc);
Result := GetLastError = 0;
end
else
begin
if SvcStatus.dwCurrentState = SERVICE_RUNNING then
begin
CloseServiceHandle(hSchSvc);
Result := True;
end
else
begin
ServiceArgVectors := nil;
//changed code here
CloseServiceHandle(hSchSvc);
hSC := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_START);
CloseServiceHandle(hSC);
if not StartService(hSchSvc, 0, ServiceArgVectors) then
begin
CloseServiceHandle(hSchSvc);
Result := GetLastError = 0;
end
else
begin
CloseServiceHandle(hSchSvc);
Result := True;
end;
end;
end;
end;
end;