关于Windows系统服务的问题 我在用Delphi开发一个系统服务控制软件,如何获得系统服务的描述信息和启动类型? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是要这个吗? function GetWinVersion: String; var VersionInfo : TOSVersionInfo; OSName : String; begin VersionInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo ); if Windows.GetVersionEx( VersionInfo ) then begin with VersionInfo do begin case dwPlatformId of VER_PLATFORM_WIN32s : OSName := 'Win32s'; VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows 95'; VER_PLATFORM_WIN32_NT : OSName := 'Windows NT'; end; Result := OSName + ' Version ' + IntToStr( dwMajorVersion ) + '.' + IntToStr( dwMinorVersion ) + #13#10' (Build ' + IntToStr( dwBuildNumber ) + ': ' + szCSDVersion + ')'; end; end else Result := ''; end; 兄弟这个是获得系统类型我是要获得系统服务的描述信息系统服务就是以SYSTEM帐户运行的服务进程明白不? function QueryServiceConfig2(hService: SC_HANDLE; dwInfoLevel: DWORD; lpBuffer: PChar; cbBufSize: DWORD; var pcbBytesNeeded: DWORD): BOOL; stdcall; external advapi32 name 'QueryServiceConfig2A';查看SvcMgr和WinSVC单元里面的代码吧。里面有很多函数可以用的。function ServiceDescription(const ServiceName: string; const Computer: PChar = nil): string;{ 返回指定服务的描述信息}const SERVICE_CONFIG_DESCRIPTION = $00000001;type TServiceDescription = packed record lpDescription: LPSTR; end; PServiceDescription = ^TServiceDescription;var SCM, SCH: SC_Handle; P: PServiceDescription; R: DWORD;begin if IsLocalComputer(Computer) then SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS) else SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS); if SCM <> 0 then begin SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS); if SCH <> 0 then begin QueryServiceConfig2(SCH, SERVICE_CONFIG_DESCRIPTION, nil, 0, R); // Get Buffer Length GetMem(P, R + 1); QueryServiceConfig2(SCH, SERVICE_CONFIG_DESCRIPTION, PChar(P), R + 1, R); Result := P.lpDescription; FreeMem(P); CloseServiceHandle(SCH); end; CloseServiceHandle(SCM); end;end;function ServiceDisplayName(const ServiceName: string; const Computer: PChar = nil): string;{ 返回指定服务的显示名称}var SCM, SCH: SC_Handle; L: DWORD;begin Result := ''; if IsLocalComputer(Computer) then SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS) else SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS); if SCM <> 0 then begin SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS); if SCH <> 0 then begin GetServiceDisplayName(SCM, PChar(ServiceName), nil, L); SetLength(Result, L); GetServiceDisplayName(SCM, PChar(ServiceName), PChar(Result), L); CloseServiceHandle(SCH); end; CloseServiceHandle(SCM); end;end;procedure ServiceNames(Names: TStrings; DisplayNames: TStrings = nil; const Service_Type: integer = $30; const Computer: PChar = nil);{ 返回系统服务列表,Names:用于接收返回的服务名称列表, DisplayName:用于接收返回的对应显示名称列表, uType:需要返回那些类型服务名称列表,可以为SERVICE_DRIVER,SERVICE_WIN32,SERVICE_ALL}type TEnumServices = array[0..0] of TEnumServiceStatus; PEnumServices = ^TEnumServices;var SCM: SC_Handle; Services: PEnumServices; Len: Cardinal; ServiceCount, ResumeHandle, i: Cardinal;begin ResumeHandle := 0; if IsLocalComputer(Computer) then SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS) else SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS); Len := 0; ServiceCount := 0; Services := nil; try Names.BeginUpdate; if Assigned(DisplayNames) then DisplayNames.BeginUpdate; if SCM <> 0 then begin EnumServicesStatus(SCM, Service_Type, SERVICE_STATE_ALL, Services[0], 0, Len, ServiceCount, ResumeHandle); GetMem(Services, Len); EnumServicesStatus(SCM, SERVICE_DRIVER or SERVICE_WIN32, SERVICE_STATE_ALL, Services[0], Len, Len, ServiceCount, ResumeHandle); for i := 0 to ServiceCount - 1 do begin Names.Add(Services[i].lpServiceName); if Assigned(DisplayNames) then DisplayNames.Add(Services[i].lpDisplayName); end; FreeMem(Services); end; finally Names.EndUpdate; if Assigned(DisplayNames) then DisplayNames.EndUpdate; CloseServiceHandle(SCM); end;end;其余的自己看着办吧。 Tsplitter怎么不让它移动? 你有过这样的经历吗?散点分 熟悉cxgrid朋友请进,关于cxgrid行选择的问题。 连接数据库问题,请各位大侠执教. 有个问题急高手帮帮忙 小女子菜,请各位高手帮一下小女子我!!!! 请问如何把TIF格式转换成JPG或GIF的格式?? 一个问题,搞的我好几个星期了,请delphi大人帮帮忙,在这先谢了。 为何ADO连接不上数据库。(在线等待) 我该怎样选择?跟者有分 关于函数调用的小问题! Ado 中的Locate方法能否可以定位到多个符合条件的记录。
function GetWinVersion: String;
var
VersionInfo : TOSVersionInfo;
OSName : String;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo ); if Windows.GetVersionEx( VersionInfo ) then begin
with VersionInfo do begin
case dwPlatformId of
VER_PLATFORM_WIN32s : OSName := 'Win32s';
VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows 95';
VER_PLATFORM_WIN32_NT : OSName := 'Windows NT';
end;
Result := OSName + ' Version ' + IntToStr( dwMajorVersion ) + '.' + IntToStr( dwMinorVersion ) +
#13#10' (Build ' + IntToStr( dwBuildNumber ) + ': ' + szCSDVersion + ')';
end;
end
else
Result := '';
end;
我是要获得系统服务的描述信息
系统服务就是以SYSTEM帐户运行的服务进程明白不?
lpBuffer: PChar; cbBufSize: DWORD; var pcbBytesNeeded: DWORD): BOOL;
stdcall; external advapi32 name 'QueryServiceConfig2A';查看SvcMgr和WinSVC单元里面的代码吧。里面有很多函数可以用的。
function ServiceDescription(const ServiceName: string; const Computer: PChar = nil): string;
{
返回指定服务的描述信息
}
const
SERVICE_CONFIG_DESCRIPTION = $00000001;
type
TServiceDescription = packed record
lpDescription: LPSTR;
end;
PServiceDescription = ^TServiceDescription;
var
SCM, SCH: SC_Handle;
P: PServiceDescription;
R: DWORD;
begin
if IsLocalComputer(Computer) then
SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS)
else
SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS);
if SCM <> 0 then
begin
SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS);
if SCH <> 0 then
begin
QueryServiceConfig2(SCH, SERVICE_CONFIG_DESCRIPTION, nil, 0, R); // Get Buffer Length
GetMem(P, R + 1);
QueryServiceConfig2(SCH, SERVICE_CONFIG_DESCRIPTION, PChar(P), R + 1, R);
Result := P.lpDescription;
FreeMem(P);
CloseServiceHandle(SCH);
end;
CloseServiceHandle(SCM);
end;
end;function ServiceDisplayName(const ServiceName: string; const Computer: PChar = nil): string;
{
返回指定服务的显示名称
}
var
SCM, SCH: SC_Handle;
L: DWORD;
begin
Result := '';
if IsLocalComputer(Computer) then
SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS)
else
SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS);
if SCM <> 0 then
begin
SCH := OpenService(SCM, PChar(ServiceName), SERVICE_ALL_ACCESS);
if SCH <> 0 then
begin
GetServiceDisplayName(SCM, PChar(ServiceName), nil, L);
SetLength(Result, L);
GetServiceDisplayName(SCM, PChar(ServiceName), PChar(Result), L);
CloseServiceHandle(SCH);
end;
CloseServiceHandle(SCM);
end;
end;procedure ServiceNames(Names: TStrings; DisplayNames: TStrings = nil;
const Service_Type: integer = $30; const Computer: PChar = nil);
{
返回系统服务列表,Names:用于接收返回的服务名称列表,
DisplayName:用于接收返回的对应显示名称列表,
uType:需要返回那些类型服务名称列表,可以为SERVICE_DRIVER,SERVICE_WIN32,SERVICE_ALL
}
type
TEnumServices = array[0..0] of TEnumServiceStatus;
PEnumServices = ^TEnumServices;
var
SCM: SC_Handle;
Services: PEnumServices;
Len: Cardinal;
ServiceCount, ResumeHandle, i: Cardinal;
begin
ResumeHandle := 0;
if IsLocalComputer(Computer) then
SCM := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS)
else
SCM := OpenSCManager(Computer, nil, SC_MANAGER_ALL_ACCESS);
Len := 0;
ServiceCount := 0;
Services := nil;
try
Names.BeginUpdate;
if Assigned(DisplayNames) then DisplayNames.BeginUpdate; if SCM <> 0 then
begin
EnumServicesStatus(SCM, Service_Type, SERVICE_STATE_ALL,
Services[0], 0, Len, ServiceCount, ResumeHandle);
GetMem(Services, Len);
EnumServicesStatus(SCM, SERVICE_DRIVER or SERVICE_WIN32, SERVICE_STATE_ALL,
Services[0], Len, Len, ServiceCount, ResumeHandle);
for i := 0 to ServiceCount - 1 do
begin
Names.Add(Services[i].lpServiceName);
if Assigned(DisplayNames) then DisplayNames.Add(Services[i].lpDisplayName);
end;
FreeMem(Services);
end;
finally
Names.EndUpdate;
if Assigned(DisplayNames) then DisplayNames.EndUpdate;
CloseServiceHandle(SCM);
end;
end;其余的自己看着办吧。