SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

StartScheduler

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent
View previous topic :: View next topic  
Author Message
Ted Tripp



Joined: 18 Aug 2006
Posts: 5

PostPosted: Mon Sep 25, 2006 6:57 pm    Post subject: StartScheduler Reply with quote

I would like to give the user the option to start the scheduling service if it is not already started. StartScheduler, Open and Active all seem to start the scheduler (if it can be started), but none seem to simply check the status.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Tue Sep 26, 2006 7:25 am    Post subject: Reply with quote

Add WinSvc in uses and use the following:
Code:
function SchedulerServiceRunning: Boolean;
const
  SCHED_CLASS = 'SAGEWINDOWCLASS';
  SCHED_TITLE = 'SYSTEM AGENT COM WINDOW';
  SCHED_SERVICE_APP_NAME = 'mstask.exe';
  SCHED_SERVICE_NAME = 'Schedule';
var
  hSC: SC_HANDLE;
  hSchSvc: SC_HANDLE;
  SvcStatus: TServiceStatus;
begin
  Result := False;
  if SysUtils.Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  begin
    Result := FindWindow(SCHED_CLASS, SCHED_TITLE) <> 0;
  end
  else
  begin
    hSC := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
    if hSC = 0 then
      Result := GetLastError = 0
    else
    begin
      hSchSvc := OpenService(hSC, SCHED_SERVICE_NAME, SERVICE_QUERY_STATUS);
      if hSchSvc = 0 then
        Exit;
      CloseServiceHandle(hSC);
      if not QueryServiceStatus(hSchSvc, SvcStatus) then
      begin
        CloseServiceHandle(hSchSvc);
        Exit;
      end
      else
      begin
        if SvcStatus.dwCurrentState = SERVICE_RUNNING then
        begin
          CloseServiceHandle(hSchSvc);
          Result := True;
        end
        else
          CloseServiceHandle(hSchSvc);
      end;
    end;
  end;
end;
Back to top
View user's profile Send private message
Ted Tripp



Joined: 18 Aug 2006
Posts: 5

PostPosted: Tue Oct 10, 2006 8:26 pm    Post subject: Reply with quote

A belated thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group