StartScheduler
StartScheduler
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.
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;
Best regards,
Igor Siticov.
Igor Siticov.