Obtaining properties of a Windows Service

  • Thread starter Thread starter B. Chernick
  • Start date Start date
B

B. Chernick

I've written some test code based on a Help example.

Assuming I get a ServiceController using the ServiceController.GetServices
call, is there any way to use that to get the executable path of the Windows
Service?
 
I assume by 'serviceIdentifier', you are refering to the ServiceName property
of the ServiceController? In any case it seems to work.
 
I've written some test code based on a Help example.

Assuming I get a ServiceController using the ServiceController.GetServices
call, is there any way to use that to get the executable path of the Windows
Service?

Hi,
If you're trying to get executable path of a Windows Service, here is
the one that i've generated for you:


' ///////////////////////////////////
'First, add reference to System.Management.dll
' Assuming you want to get "Messenger" service's path
'Import Management namespace
Imports System.Management


Dim searcher As New ManagementObjectSearcher _
("root\CIMV2", "SELECT * FROM Win32_Service Where Name=""Messenger""")

For Each queryObj As ManagementObject In searcher.Get()

' For example, get path in a messagebox
MsgBox(queryObj.GetPropertyValue("PathName").ToString)

Next
' ///////////////////////

Just change, "Messenger" service name in query command to another
which one you desire to get executable path.

Hope this helps,

Onur Güzel
 
Back
Top