发新话题
打印

[转载]取得系统已安装的NTService

[转载]取得系统已安装的NTService

  信息来源:邪恶八进制
  
  这东西好像不错................................

相關Api:  EnumServicesStatus

The EnumServicesStatus function enumerates services in the specified service control manager database. The name and status of each service are provided.

This function has been superseded by the EnumServicesStatusEx function. It returns the same information EnumServicesStatus returns, plus the process identifier and additional information for the service. In addition, EnumServicesStatusEx enables you to enumerate services that belong to a specified group.


BOOL EnumServicesStatus(
  SC_HANDLE hSCManager,
  DWORD dwServiceType,
  DWORD dwServiceState,
  LPENUM_SERVICE_STATUS lpServices,
  DWORD cbBufSize,
  LPDWORD pcbBytesNeeded,
  LPDWORD lpServicesReturned,
  LPDWORD lpResumeHandle
);

sample:

function ServiceGetList(sMachine: string; dwServiceType,
  dwServiceState: DWord; slServicesList: TStrings): boolean;
var
  j: integer;
  schm: SC_Handle;
  nBytesNeeded, nServices, nResumeHandle: DWord;
  ServiceStatusRecs: array[0..511] of TEnumServiceStatus;
begin
  Result := false;
  schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_ALL_ACCESS);
  try
   if (schm = 0) then Exit;
   nResumeHandle := 0;
   while True do
   begin
    EnumServicesStatus(schm, dwServiceType, dwServiceState, @ServiceStatusRecs[0], sizeof(ServiceStatusRecs),
      @nBytesNeeded, @nServices, @nResumeHandle);
    for j := 0 to nServices - 1 do
    begin
      slServicesList.Add(ServiceStatusRecs[j].lpDisplayName + '---' + ServiceStatusRecs[j].lpServiceName);
    end;
    if nBytesNeeded = 0 then Break;
   end;
   Result := true;
  finally
   if schm > 0 then
    CloseServiceHandle(schm);
  end;
end;

procedure TForm1.btnServiceGetListClick(Sender: TObject);
begin
  ServiceGetList('', SERVICE_WIN32, SERVICE_STATE_ALL, lbServices.Items);
end;
在我纯真年少時,有一個女生,她願意爲我失去生命,她意志堅定地說:你再纏著我,我就去死! 在我負笈外地時,有一個女生,她願意等我到下輩子,她溫柔婉約地說:你想成爲我男友?等下輩子!! 在我窮困潦倒時,有一個女生,她願意與我共赴黃泉,她眨著紅眼說:你再不還錢,我和你同歸于盡!

TOP

发新话题