Page 1 of 1
StartScheduler
Posted: Mon Sep 25, 2006 6:57 pm
by Ted Tripp
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.
Posted: Tue Sep 26, 2006 7:25 am
by isiticov
Add WinSvc in uses and use the following:
Code: Select all
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;
Posted: Tue Oct 10, 2006 8:26 pm
by Ted Tripp
A belated thanks