Delphi

[Delphi] 특정 서비스 프로그램 실행여부 확인

그저심 2022. 10. 13. 10:21
// uses WinSvc

function ServiceGetStatus(sMachine, sService: PChar): DWORD;
{******************************************}
{*** Parameters: ***}
{*** sService: specifies the name of the service to open
{*** sMachine: specifies the name of the target computer
{*** ***}
{*** Return Values: ***}
{*** -1 = Error opening service ***}
{*** 1 = SERVICE_STOPPED ***}
{*** 2 = SERVICE_START_PENDING ***}
{*** 3 = SERVICE_STOP_PENDING ***}
{*** 4 = SERVICE_RUNNING ***}
{*** 5 = SERVICE_CONTINUE_PENDING ***}
{*** 6 = SERVICE_PAUSE_PENDING ***}
{*** 7 = SERVICE_PAUSED ***}
{******************************************}
var
  SCManHandle, SvcHandle: SC_Handle;
  SS: TServiceStatus;
  dwStat: DWORD;
begin
  dwStat := 0;

  // Open service manager handle.
  SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);
  if (SCManHandle > 0) then
  begin
    SvcHandle := OpenService(SCManHandle, sService, SERVICE_QUERY_STATUS);
    // if Service installed
    if (SvcHandle > 0) then
    begin
      // SS structure holds the service status (TServiceStatus);
      if (QueryServiceStatus(SvcHandle, SS)) then
        dwStat := ss.dwCurrentState;
      CloseServiceHandle(SvcHandle);
    end;
    CloseServiceHandle(SCManHandle);
  end;
  Result := dwStat;
end;

function CheckServiceRunning(sMachine, sService: PChar): Boolean;
begin
  Result := SERVICE_RUNNING = mServiceGetStatus(sMachine, sService);
end;

 

https://iwittooh.tistory.com/7429973

 

특정 서비스가 실행되는지 여부 체크하기

{ - Torry에서 퍼왔습니다. - 서버의 특정 서비스가 실행되는지 여부를 체크할 수 있습니다. 현재 이 프로그램에서는 MS SQL SERVER가 정상적으로 시작 되었는지를 체크 합니다. } unit Unit1; interface uses W

iwittooh.tistory.com

 

반응형

'Delphi' 카테고리의 다른 글

[Delphi] 마우스 커서 변경  (0) 2022.11.09
[Delphi] Save string into Text File  (0) 2022.11.03
[Delphi] PC Sound Control  (0) 2022.10.08
[Delphi] TIniFile 클래스  (0) 2022.09.14
[Delphi] 모달, 모달리스 폼 띄우기  (0) 2022.09.05