获取服务的描述?
如何获取如下所示的 Windows 服务的描述?
我尝试过通过使用 Windows 注册表,但大多数服务似乎没有描述,或者描述值存储在 dll 中 - 所以这似乎是错误的方法。
示例:
Windows 时间服务(W32Time),在注册表中的描述显示为
@%SystemRoot%\system32\w32time.dll,-201
但在 Services.msc 中看到的实际描述是:
保持所有客户端和服务器上的日期和时间同步 网络。如果此服务停止,日期和时间同步 将不可用。如果此服务被禁用,则任何服务 显式依赖它将无法启动。
-
我一直在 MSDN 网站上搜索并发现了这个:
lp描述
服务的描述。如果该成员为 NULL,则 描述保持不变。如果该值为空字符串 (""), 当前描述被删除。
服务描述不得超过注册表值的大小 类型为 REG_SZ。
该成员可以使用以下格式指定本地化字符串:
@[路径]dllname,-strID
从dllname加载标识符为strID的字符串;路径是 选修的。有关详细信息,请参阅 RegLoadMUIString< /a>....
-
pszOutBuf [输出,可选]
指向接收字符串的缓冲区的指针。
以下形式的字符串接受特殊处理:
@[路径]\dllname,-strID
从dllname加载标识符为strID的字符串;路径是 选修的。如果 pszDirectory 参数不为 NULL,则目录为 添加到注册表数据中指定的路径之前。注意 dllname可以包含要扩展的环境变量。
我认为这可以说明为什么查看注册表将 W32Time 描述显示为 @%SystemRoot%\system32\w32time.dll,-201
如果我理解正确,我需要读取内存中的 dll 名称并检索存储服务描述的 strID ?
这对我来说很困惑,如果有人能提供帮助,我将不胜感激。
我所需要的只是获取服务的描述,它肯定不能像这样复杂,可以吗?
谢谢 :)
How may I get the description of a Windows Service like below?
I tried by using the Windows Registry, but the majority of Services appear to not have a description, or the description value is stored in a dll - so this seems to be the wrong approach.
Example:
Windows Time Service (W32Time), the description in the registry is shown as
@%SystemRoot%\system32\w32time.dll,-201
Yet the actual description as seen in Services.msc is:
Maintains date and time synchronization on all clients and servers in
the network. If this service is stopped, date and time synchronization
will be unavailable. If this service is disabled, any services that
explicitly depend on it will fail to start.
-
I have been searching on the MSDN website and came across this:
lpDescription
The description of the service. If this member is NULL, the
description remains unchanged. If this value is an empty string (""),
the current description is deleted.The service description must not exceed the size of a registry value
of type REG_SZ.This member can specify a localized string using the following format:
@[path]dllname,-strID
The string with identifier strID is loaded from dllname; the path is
optional. For more information, see RegLoadMUIString....-
pszOutBuf [out, optional]
A pointer to a buffer that receives the string.
Strings of the following form receive special handling:
@[path]\dllname,-strID
The string with identifier strID is loaded from dllname; the path is
optional. If the pszDirectory parameter is not NULL, the directory is
prepended to the path specified in the registry data. Note that
dllname can contain environment variables to be expanded.
Which I think would suggest why viewing the Registry showed the W32Time description as @%SystemRoot%\system32\w32time.dll,-201
If I understand correctly I need to read the dll name in memory and retrieve the strID where the Service description is stored?
This is all confusing for me, I would be grateful if someone could help.
All I need is to get the description of a Service, it surely cannot be as complicated as this can it?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Delphi 的所有版本中,JEDI JCL 包含您需要的所有内容获取服务的友好描述以及与服务控制 API 相关的任何其他内容。
JclSvcCtrl.pas 单元中的 TJclSCManager 类包含一个属性 Services,其中包括注册的每个服务的名称和描述,并且还允许您执行启动、停止、启用和禁用服务等操作。
更新:ldsandon 的另一个答案指出,Delphi RTL 显然已经在 XE2 的 WinSvc 单元中包含了这一点。请参阅下面有关 QueryServiceConfig2 的答案。感谢 ldsandon 指出了这一事实。
In all versions of Delphi, the the JEDI JCL contains everything you need to get friendly descriptions of services, and anything else to do with the Service Control APIs.
THe class TJclSCManager in the unit JclSvcCtrl.pas contains a property Services, which includes name and description of each service registered, and lets you also do things like start, stop, enable, and disable services too.
Update: The other answer here from ldsandon points out that the Delphi RTL apparently includes this already in XE2, in the unit WinSvc. See answer below about QueryServiceConfig2. Thanks ldsandon for pointing this fact out.
调用 QueryServiceConfig2 (您还可以在那里找到一个 C 示例)。
无论您需要对服务执行什么操作,都应该通过 服务管理器 API。注册表数据应被视为操作系统的“私有”数据。
Call QueryServiceConfig2 (you will find also a C example there).
Whatever you need to do with services should be done through the Service Manager API. Registry data should be treated as "private" to the OS.
使用 WMI 是直接使用 Windows API 的另一种方法,例如借助(免费)API 代码生成器
WMI Delphi 代码创建者
Using WMI is another way to use the Windows API directly, for example with the help of the (free) API code generator
WMI Delphi Code Creator
您使用的是统一码吗? RegLoadMUIString 函数的备注< /a> 表示仅支持 Unicode 版本。
您是否尝试过直接调用
RegLoadMUIStringW
?Are you using Unicode? The remarks for the RegLoadMUIString function say that only the Unicode version is supported.
Have you tried calling
RegLoadMUIStringW
directly?您还可以查看GLibWMI 库。用于与 WMI 配合使用的免费(且包含源代码)库。包含名为 TServiceInfo 的组件。
还包括一个用于工作服务的演示。
使用此组件,您可以在 Win32_Service 类中访问;您可以检查属性和结构在这里。
问候
You also can check the GLibWMI library. Free (and source included) library for work with WMI. Include a component named TServiceInfo.
Also is included a demo for work wirh services.
With this component you can access at Win32_Service Class; You can check the properties and structure here.
Regards