编程获取正在运行的服务的程序集的版本 [英] Programmatically retrieving assembly version of a running service

查看:221
本文介绍了编程获取正在运行的服务的程序集的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问一个服务,我的控制与ServiceController的类的程序集的版本信息。 (即我想显示2.3.1.23),但是我无法找到有关检索集版本的任何信息......有没有可能呢?

I'd like to access to assembly version information of a service I "control" with ServiceController class. (ie. I'd like to display "2.3.1.23" ), however I can't find any information about retrieving assembly versions ... Is it possible at all?

修改:只是为了澄清...我只知道在本地计算机上运行的服务的名称。我想访问FileVersionInfo即服务(还好说服务EXE),但是我不知道哪里是位于该服务exe文件。

EDIT: Just to clarify ... I only know the name of the service running on the local computer. I want to access the "FileVersionInfo" of that service (better said service exe), however I don't know where is that service exe located.

推荐答案

如果我理解正确,你想要得到任何服务exe文件的版本。假设你知道的名称和服务的可执行文件的路径,你可能会想尝试:

If I understand you correctly, you want to get the version of any service exe. Assuming that you know the name and path of the service's executable, you might want to try:

FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(<path and name of service exe>);

您可以再使用 FileVersionInfo 类显示的版本号。请注意,这也适用于UNC路径,只要你有阅读权限访问该文件。

You can then use the properties of the FileVersionInfo class to show the version number. Please note that this also works for UNC paths as long as you have permissions to read-access the file.

修改

要获得可执行文件的路径和名称,如果你只知道服务的名称,您可以访问在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services 注册表。搜索相匹配的服务名称的关键。根据该键,有一个值名称的ImagePath 包含可执行文件的名称和路径。

EDIT
To get the executable path and name if you only know the service name, you can access the Registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. Search a key that matches the service name. Under that key, there's a value name ImagePath that contains the executable's name and path.

这篇关于编程获取正在运行的服务的程序集的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆