Cannot run task scheduler under non-admin accounts.

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
shaune
Posts: 6
Joined: Mon Apr 19, 2004 7:59 am

Cannot run task scheduler under non-admin accounts.

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

Post 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.
shaune
Posts: 6
Joined: Mon Apr 19, 2004 7:59 am

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

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

Post by isiticov »

Also could you please test if the demo application included into delivery fails to work under restricted account as well?
shaune
Posts: 6
Joined: Mon Apr 19, 2004 7:59 am

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

Post by isiticov »

How does the demo application work under restricted account?
shaune
Posts: 6
Joined: Mon Apr 19, 2004 7:59 am

Post 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
mike71
Posts: 4
Joined: Tue Jan 18, 2005 8:30 am

Post 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.
mike71
Posts: 4
Joined: Tue Jan 18, 2005 8:30 am

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

Post by isiticov »

Thank you for details. We will try to investigate what could be a reason for this.
bartonkt
Posts: 1
Joined: Thu Mar 10, 2005 10:34 pm

Post 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;
Post Reply