program Project1; {$APPTYPE CONSOLE} uses
Windows,
WinSvc; type
SERVICE_DESCRIPTION = packed record
lpDescription: PWChar;
end;
PSERVICE_DESCRIPTION = ^SERVICE_DESCRIPTION; function QueryServiceConfig2(hService: THandle; dwInfoLevel: DWORD; lpBuffer: Pointer; cbBufSize: DWORD; var pcbBytesNeeded: DWORD): LongBool; stdcall; external 'advapi32.dll' name 'QueryServiceConfig2W'; ////////////////////////////////////////////////////////////////////////////////
// Procedure : SysErrorMessage
// Comment : Returns last error as formated string function SysErrorMessage(ErrorCode: Integer): string;
var
Len: Integer;
Buffer: array[..]of Char;
begin
Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ARGUMENT_ARRAY,
nil, ErrorCode, , Buffer, SizeOf(Buffer), nil);
while (Len > )and(Buffer[Len-] in [#..#, '.']) do Dec(Len);
SetString(Result, Buffer, Len);
end; function GetServiceDesciption(Computer, Servicename: PWChar; var Description: WideString): Boolean;
var
sc: THandle;
os: THandle;
sd: Boolean;
dwNeeded: DWORD;
Buffer: Pointer;
begin
dwNeeded := ;
Buffer := nil;
sc := OpenSCManagerW(Computer, nil, SC_MANAGER_CONNECT);
if sc <> then
begin
os := OpenServiceW(sc, Servicename, SERVICE_QUERY_CONFIG);
if os <> then
begin
sd := QueryServiceConfig2(os, , nil, , dwNeeded);
if (not sd) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
begin
try
GetMem(Buffer, dwNeeded);
result := QueryServiceConfig2(os, , Buffer, dwNeeded, dwNeeded);
if result then
begin
Description := PSERVICE_DESCRIPTION(Buffer)^.lpDescription;
end;
finally
FreeMem(Buffer, dwNeeded);
end;
end
else
result := False;
end
else
result := False;
end
else
result := False;
end; var
description : WideString; begin
if not GetServiceDesciption('PC-201212071904', 'AdobeFlashPlayerUpdateSvc', description) then
begin
Writeln(SysErrorMessage(GetLastError));
Readln;
end
else
MessageBoxW(, PWideChar(description), 'Dienstbeschreibung', ); end.
http://www.lsworks.net/article/97.html