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?

Re: Obtaining properties of a Windows Service by Michael

Michael
Tue Jul 15 10:40:01 CDT 2008

On 15 Jul., 17:11, B. Chernick <BChern...@discussions.microsoft.com>
wrote:
> 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?

This might be of interest to you:

http://www.codeproject.com/KB/system/extendservicecontroller.aspx

I guess you can easily expand it to return the application executable.

Michael


Re: Obtaining properties of a Windows Service by BChernick

BChernick
Tue Jul 15 12:00:02 CDT 2008

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

"Stanimir Stoyanov" wrote:

> .NET Framework does not provide a property for this but you can fetch the
> raw value from the registry with a line such as this:
>
> Dim imagePath as String =
> Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"
> & serviceIdentifier, "ImagePath", "")
>
> where serviceIdentifier is the identifier of the service (not its display
> name). It will return an empty string in case the key or entry is not found
> (third argument in the call).
>
> Best Regards,
> Stanimir Stoyanov
> www.stoyanoff.info
>
> "B. Chernick" <BChernick@discussions.microsoft.com> wrote in message
> news:005EF3D1-168E-4236-881E-EAB7758EA5BA@microsoft.com...
> > 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?
>

Re: Obtaining properties of a Windows Service by kimiraikkonen

kimiraikkonen
Tue Jul 15 12:38:57 CDT 2008

On Jul 15, 6:11 pm, B. Chernick <BChern...@discussions.microsoft.com>
wrote:
> I've written some test code based on a Help example.
>
> Assuming I get a ServiceController using the ServiceController.GetService=
s
> call, is there any way to use that to get the executable path of the Wind=
ows
> 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=3D""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=FCzel