Question

I have this Windows Service from my company :

enter image description here

I want to get the service description from it in code behind! but for some reason it does not return the service description.

Can anyone help me with this .

here is my code, and what it returns :

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

and what the MyService variable returns.

enter image description here

How would i get the Service Description from here?

Regards,

EDIT:

Here is my code after Miki Shah pointed me in the right direction!

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
Était-ce utile?

La solution

You can get as following way, and have to add reference of 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"]);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top