Q&A

  • 윈도2000서비스등록 프로그램이 실행중인지 아닌지 어떻게 알수 잇나요

윈도2000서비스 등록 프로그램이 실행중인지 아닌지 알아낼려고 한는데요

서비스 등록 프로그램이 실행중이면. 화면을 만들어서 상태를 보여줄려고 합니다.


알려주세요.. 게시판을  전부 보았는데도 없네요


1  COMMENTS
  • Profile
    강인규 2003.03.20 21:03
    uses WinSvc;


    function TForm1.GetServiceStatus(const ServiceName: string): DWORD;
    var
      schService, schSCManager: DWORD;
      ServiceStatus: TServiceStatus;
    begin
      schSCManager := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
      if schSCManager = 0 then RaiseLastWin32Error;
      try
        schService := OpenService(schSCManager, PChar(ServiceName),
          SERVICE_QUERY_STATUS or SERVICE_QUERY_CONFIG);
        if schService = 0 then RaiseLastWin32Error;
         try
          if not QueryServiceStatus(schService, ServiceStatus) then
            RaiseLastWin32Error;

          Result := ServiceStatus.dwCurrentState;
        finally
          CloseServiceHandle(schService);
        end;
      finally
        CloseServiceHandle(schSCManager);
      end;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      case GetServiceStatus('Messenger') of
        SERVICE_STOPPED, SERVICE_STOP_PENDING:
          begin
            Caption := 'It''s Stoped';
          end;

        SERVICE_START_PENDING, SERVICE_CONTINUE_PENDING, SERVICE_RUNNING:
          begin
            Caption := 'It''s Running';
          end;

        SERVICE_PAUSE_PENDING, SERVICE_PAUSED:
          begin
            Caption := 'It''s Paused';
          end;
      end;
    end;

    have a nice day :D