Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ServiceStop(aMachine, aServiceName: string): boolean;
- // aMachine это UNC путь, либо локальный компьютер если пусто
- var
- h_manager, h_svc: SC_Handle;
- svc_status: TServiceStatus;
- dwCheckPoint: DWord;
- begin
- h_manager := OpenSCManager(PChar(aMachine), nil, SC_MANAGER_CONNECT);
- if h_manager > 0 then
- begin
- h_svc := OpenService(h_manager, PChar(aServiceName), SERVICE_STOP or SERVICE_QUERY_STATUS);
- if h_svc > 0 then
- begin
- if (ControlService(h_svc, SERVICE_CONTROL_STOP, svc_status)) then
- begin
- if (QueryServiceStatus(h_svc, svc_status)) then
- begin
- while (SERVICE_STOPPED <> svc_status.dwCurrentState) do
- begin
- dwCheckPoint := svc_status.dwCheckPoint;
- Sleep(svc_status.dwWaitHint);
- if (not QueryServiceStatus(h_svc, svc_status)) then
- begin// couldn't check status
- break;
- end;
- if (svc_status.dwCheckPoint < dwCheckPoint) then
- break;
- end;
- end;
- end;
- CloseServiceHandle(h_svc);
- end;
- CloseServiceHandle(h_manager);
- end;
- Result := SERVICE_STOPPED = svc_status.dwCurrentState;
- end;
- //применение
- //ServiceStop(string.empty, 'OkayFreedom VPN Starter Service');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement