Thema: Delphi EnumServicesStatusEx

Einzelnen Beitrag anzeigen

schwa226

Registriert seit: 4. Apr 2008
400 Beiträge
 
#2

Re: EnumServicesStatusEx

  Alt 7. Dez 2009, 15:02
Habe es mir nun selber zusammen geschrieben:

Delphi-Quellcode:
type
  PServiceStatusEx = ^TServiceStatusEx;
  {$EXTERNALSYM _SERVICE_STATUS_EX}
  _SERVICE_STATUS_EX = record
    dwServiceType: DWORD;
    dwCurrentState: DWORD;
    dwControlsAccepted: DWORD;
    dwWin32ExitCode: DWORD;
    dwServiceSpecificExitCode: DWORD;
    dwCheckPoint: DWORD;
    dwWaitHint: DWORD;
    dwProcessId : DWORD;
    dwServiceFlags: DWORD;
  end;
  {$EXTERNALSYM SERVICE_STATUS_EX}
  SERVICE_STATUS_EX = _SERVICE_STATUS_EX;
  TServiceStatusEx = _SERVICE_STATUS_EX;

//
// Service Status Enumeration Structure
//
  PEnumServiceStatusExA = ^TEnumServiceStatusExA;
  PEnumServiceStatusExW = ^TEnumServiceStatusExW;
  PEnumServiceStatusEx = PEnumServiceStatusExW;
  {$EXTERNALSYM _ENUM_SERVICE_STATUSA_EX}
  _ENUM_SERVICE_STATUSA_EX = record
    lpServiceName: PAnsiChar;
    lpDisplayName: PAnsiChar;
    ServiceStatus: TServiceStatusEx;
  end;
{#BEGIN}
  {$EXTERNALSYM ENUM_SERVICE_STATUSA_EX}
  ENUM_SERVICE_STATUSA_EX = _ENUM_SERVICE_STATUSA_EX;
  {$EXTERNALSYM _ENUM_SERVICE_STATUSW_EX}
  _ENUM_SERVICE_STATUSW_EX = record
    lpServiceName: PWideChar;
    lpDisplayName: PWideChar;
    ServiceStatus: TServiceStatusEx;
  end;
{#BEGIN}
  {$EXTERNALSYM ENUM_SERVICE_STATUSW_EX}
  ENUM_SERVICE_STATUSW_EX = _ENUM_SERVICE_STATUSW_EX;
  {$EXTERNALSYM _ENUM_SERVICE_STATUS_EX}
  _ENUM_SERVICE_STATUS_EX = _ENUM_SERVICE_STATUSW_EX;
  TEnumServiceStatusExA = _ENUM_SERVICE_STATUSA_EX;
  TEnumServiceStatusExW = _ENUM_SERVICE_STATUSW_EX;
  TEnumServiceStatusEx = TEnumServiceStatusExW;

{$EXTERNALSYM EnumServicesStatusEx}
function EnumServicesStatusEx(hSCManager: SC_HANDLE;
  InfoLevel : SC_ENUM_TYPE;
  dwServiceType,
  dwServiceState: DWORD; var lpServices: TEnumServiceStatusEx; cbBufSize: DWORD;
  var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD;
  pszGroupName : PWideChar): BOOL; stdcall;
{$EXTERNALSYM EnumServicesStatusExA}
function EnumServicesStatusExA(hSCManager: SC_HANDLE;
  InfoLevel : SC_ENUM_TYPE;
  dwServiceType,
  dwServiceState: DWORD; var lpServices: TEnumServiceStatusExA; cbBufSize: DWORD;
  var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD;
  pszGroupName : PChar): BOOL; stdcall;
{$EXTERNALSYM EnumServicesStatusExW}
function EnumServicesStatusExW(hSCManager: SC_HANDLE;
  InfoLevel : SC_ENUM_TYPE;
  dwServiceType,
  dwServiceState: DWORD; var lpServices: TEnumServiceStatusExW; cbBufSize: DWORD;
  var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD;
  pszGroupName : PWideChar): BOOL; stdcall;

function EnumServicesStatusEx; external advapi32 name 'EnumServicesStatusExW';
function EnumServicesStatusExA; external advapi32 name 'EnumServicesStatusExA';
function EnumServicesStatusExW; external advapi32 name 'EnumServicesStatusEXW';
Aufruf:
Delphi-Quellcode:
type
  TSvcA = array[0..cnMaxServices]
          of TEnumServiceStatusEx;
  PSvcA = ^TSvcA;

  // service status array
  ssa : PSvcA;

    EnumServicesStatusEx(
      schm,
      SC_ENUM_PROCESS_INFO,
      SERVICE_WIN32,
      SERVICE_ACTIVE,
      ssa^[0],
      SizeOf(ssa^),
      nBytesNeeded,
      nServices,
      nResumeHandle,
      nil);
Damit kann man nun die PID der laufenden Services abfragen.
Delphi 2010, Update 4 & 5
  Mit Zitat antworten Zitat