获取Windows服务的配置信息
procedure QuerySvcConfig(Service: String; out config: TQueryServiceConfig);
var
schm,
schs: SC_Handle;
ss: TServiceStatus;
dwChkP: DWord;
sConfig: PQueryServiceConfigA;
sNeeded: Cardinal;
begin
schm := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if (schm > 0) then
begin
schs := OpenService(schm, PChar(Service), SERVICE_QUERY_CONFIG);
if (schs > 0) then
begin
//Call the QueryServiceConfig function to get the required buffer size
if QueryServiceConfig(schs,sConfig,0,sNeeded) <> TRUE then
begin
if GetLastError = ERROR_INSUFFICIENT_BUFFER then
begin
//Get the memory required by using the Bytes needed var
GetMem(sConfig, sNeeded);
try
if QueryServiceConfig(schs,sConfig,sNeeded,sNeeded) <> TRUE then
begin
MessageBox(Application.Handle, PChar(SysErrorMessage(GetLastError)),
PChar(Application.Title), MB_OK + MB_ICONEXCLAMATION);
end
else
begin
//Play with Config Info here
config := sConfig^;
end;
finally
FreeMem(sConfig, sNeeded);
end;
end;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
end;
var
schm,
schs: SC_Handle;
ss: TServiceStatus;
dwChkP: DWord;
sConfig: PQueryServiceConfigA;
sNeeded: Cardinal;
begin
schm := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if (schm > 0) then
begin
schs := OpenService(schm, PChar(Service), SERVICE_QUERY_CONFIG);
if (schs > 0) then
begin
//Call the QueryServiceConfig function to get the required buffer size
if QueryServiceConfig(schs,sConfig,0,sNeeded) <> TRUE then
begin
if GetLastError = ERROR_INSUFFICIENT_BUFFER then
begin
//Get the memory required by using the Bytes needed var
GetMem(sConfig, sNeeded);
try
if QueryServiceConfig(schs,sConfig,sNeeded,sNeeded) <> TRUE then
begin
MessageBox(Application.Handle, PChar(SysErrorMessage(GetLastError)),
PChar(Application.Title), MB_OK + MB_ICONEXCLAMATION);
end
else
begin
//Play with Config Info here
config := sConfig^;
end;
finally
FreeMem(sConfig, sNeeded);
end;
end;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
end;