uses Winsvc, ExtCtrls, ComCtrls
function GetServiceExecutablePath(strMachine: string; strServiceName: string): String;
var
hSCManager,hSCService: SC_Handle;
lpServiceConfig: PQueryServiceConfigA;
nSize, nBytesNeeded: DWord;
begin
Result := '';
hSCManager := OpenSCManager(PChar(strMachine), nil, SC_MANAGER_CONNECT);
if (hSCManager > 0) then
begin
hSCService := OpenService(hSCManager, PChar(strServiceName), SERVICE_QUERY_CONFIG);
if (hSCService > 0) then
begin
QueryServiceConfig(hSCService, nil, 0, nSize);
lpServiceConfig := AllocMem(nSize);
try
if not QueryServiceConfig(
hSCService, lpServiceConfig, nSize, nBytesNeeded) Then Exit;
Result := lpServiceConfig^.lpBinaryPathName;
finally
Dispose(lpServiceConfig);
end;
CloseServiceHandle(hSCService);
end;
end;
end;
Beispiel :
procedure TForm1.ButtonClick(Sender: TObject);
var
ServicePath : string;
begin
if Edit1.Text = '' then Exit;
ServicePath := GetServiceExecutablePath('', Edit1.Text);
Label1.Caption := ServicePath;
end;
Keine Kommentare:
Kommentar veröffentlichen