Obtaining properties of a Windows Service

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?
 
B

B. Chernick

I assume by 'serviceIdentifier', you are refering to the ServiceName property
of the ServiceController? In any case it seems to work.
 
K

kimiraikkonen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top