0

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
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Arrie
  • 1,327
  • 5
  • 18
  • 39

1 Answers1

1

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"]);
}
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Miki Shah
  • 815
  • 9
  • 20
  • this is C#, i cant seem to get the Managmentobject in vb.net... and i don't understand this code completely? if you care to explain. and thanks for the effort. – Arrie Apr 24 '13 at 10:55
  • nevermind, i got the code to work, but i still dont understand, what this code does? do i give my variable this service as property? – Arrie Apr 24 '13 at 11:01
  • 1.you have to add System.Management reference, 2. Code is using main ManagementObject which is used to get information related to system. here we have service name, now we get service information using ManagmentObject class. WMI process is very good.pls refer if you not aware about this http://msdn.microsoft.com/en-us/library/dwd0y33x.aspx – Miki Shah Apr 24 '13 at 11:16