如何判断控制面板-管理工具-服务中有没有某个服务?delphi

解决方案 »

  1.   

    用EnumServicesStatus找,貌似winsvc单元的有bug,要用jedi封装的Jwawinsvc单元里面的
      

  2.   


    uses
      WinSvc;function ES(const AServiceName: string): Boolean;
    var
      hSM, schService: SC_HANDLE;
    begin
      Result := False;
      hSM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
      try
        if (hSM = 0) then
          Exit;
        schService := OpenService(hSM, PChar(AServiceName), SERVICE_ALL_ACCESS);
        try
          Result := schService <> 0;
        finally
          CloseServiceHandle(schService);
        end;
      finally
        CloseServiceHandle(hSM);
      end;
    end;