473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Obtaining properties of a Windows Service

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?
Jul 15 '08 #1
3 2500
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...ontroller.aspx

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

Michael

Jul 15 '08 #2
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_MACH INE\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" <BC*******@discussions.microsoft.comwrote in message
news:00**********************************@microsof t.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?
Jul 15 '08 #3
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.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").ToStr ing)

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
Jul 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dennis Stew | last post by:
How do I access Public variables within a Windows Service? I can, and have, created installed and executed a basic Service. From my client App I can Start, Stop...etc the service.... What I want...
6
by: Shaun Heveron | last post by:
Hi, I'm working on a portable ANSI C++ application designed to compile and execute under Windows and LINUX/UNIX. Is there a portable way of obtaining the current working directory? Sorry, if...
0
by: Piotr Szukalski | last post by:
Hi! Perhaps somebody knows how to add my own tab to Windows Service's properties box (Control Panel->Administrative Tools->Services:Properties)? I found some information that C# is not the best...
0
by: R3n H03k | last post by:
Hi all, I am installing a few web services on Windows 2003 Server. To allow a service to run, the service directory should be selected in the IIS Manager tool and the directory properties should...
0
by: CBidwill | last post by:
Hello, I'm trying to work with a web service in Visual Studio 2005 in C#. I need to use a custom tool for an xml file, which I did previously in a Windows app by accessing the properties of the...
2
by: Jan Eliasen | last post by:
Hi I am having some problems reading configuration values from a configuration file, using C# 2.0. I have programmed a Windows Service, and this part goes well - it runs nicely. Now, the...
1
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
How do I access public properties in a windows service, from a desktop application written in vb 2005? -- Sean McIntire
7
by: =?Utf-8?B?Sm9obiBTdGFnZ3M=?= | last post by:
Hello, Please read this all before giving an answer :) I'm doing some troubleshooting on a web application that my company wrote. It's written in asp.net 1.1. The error that the Event viewer...
1
by: Nemisis | last post by:
Hi everyone, I believe this is possible as i think this is how anti-virus works, i have created a windows service with a couple public readonly properties and i would like to read these...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.