0

我有我公司的这个 Windows 服务:

在此处输入图像描述

我想在后面的代码中从中获取服务描述!但由于某种原因,它不返回服务描述。

谁能帮我这个 。

这是我的代码,它返回什么:

Dim MyServices As ServiceController = New ServiceController("AccTech Exchange Rate Import")
    Dim Status As String = MyServices.Status.ToString
    Dim Name As String = MyServices.ServiceName

以及 MyService 变量返回的内容。

在此处输入图像描述

我如何从这里获得服务描述?

问候,

编辑:

这是 Miki Shah 为我指明正确方向后的代码!

Dim MyServices As ServiceController = New ServiceController("AccTech Exchange Rate Import")

Dim Status As String = MyServices.Status.ToString
Dim Name As String = MyServices.ServiceName
Dim Description As String

Dim objPath As String = String.Format("Win32_Service.Name='{0}'", Name)
Using service As New ManagementObject(New ManagementPath(objPath))
    Description = service("Description")
End Using
4

1 回答 1

1

您可以通过以下方式获得,并且必须添加 System.Management 的引用

string serviceName = MyServices.ServiceName
string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
    Console.WriteLine(service["Description"]);
}
于 2013-04-24T10:18:42.370 回答