Page 1 of 1

Cannot run task scheduler under non-admin accounts.

Posted: Wed Jun 02, 2004 11:26 am
by shaune
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.

Posted: Wed Jun 02, 2004 1:15 pm
by isiticov
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.

Posted: Thu Jun 03, 2004 8:34 am
by shaune
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.

Posted: Thu Jun 03, 2004 1:44 pm
by isiticov
Could you please specify what OS do you use?
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; 

Posted: Thu Jun 03, 2004 1:45 pm
by isiticov
Also could you please test if the demo application included into delivery fails to work under restricted account as well?

Posted: Thu Jun 03, 2004 2:12 pm
by shaune
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.

Posted: Fri Jun 04, 2004 6:39 am
by isiticov
How does the demo application work under restricted account?

Posted: Fri Jun 04, 2004 9:19 am
by shaune
Hi

The limited user account result :

once you run the program and click on the button you immediatly get the error :

'Task Scheduler service is not running'

no showmessage is executed.

I will try to run the demo application on some other Operating systems.

thanks

Posted: Tue Jan 18, 2005 6:38 pm
by mike71
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.

Posted: Wed Jan 19, 2005 5:39 pm
by mike71
This seems to be an issue just with the Trial version for me. When I ran the registered version, the problem went away.

Posted: Wed Jan 19, 2005 8:01 pm
by isiticov
Thank you for details. We will try to investigate what could be a reason for this.

Posted: Fri Mar 11, 2005 3:52 pm
by bartonkt
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;