473,385 Members | 1,908 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,385 software developers and data experts.

Get path for install service

Scenario:

I have a service which has been installed in the service component
manager.

I am writing a second program (completely unrelated to the service)
which will run stand alone. I can find all of the services on the
machine with the following line of code:

System.ServiceProcess.ServiceController[] foo =
System.ServiceProcess.ServiceController.GetService s();

My question / problem is:

Is there a way for me to use the information returned by the method
call for an instance of a service (a particular service which I know
the name) to map that back to the pathname for the installed service?

If not, does anyone have any suggestions on a different approach to the
problem???

I am using C# (and accordingly .NET)
Thanks -

Tim Burda

Nov 17 '05 #1
5 13478
Hi,

I'm not very clear of what you want in the first place, you can use the
registry to get extra info not supplied by the ServiceController class, use
the code below for that. Take a look in the registry and see what other nifo
you need.
string[] st = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services").GetSubKeyNa mes();
StringBuilder sb = new StringBuilder();
foreach( string key in st )
{

object imagePath;
object DisplayName;

if ( (imagePath =Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services\\" + key).GetValue( "ImagePath"))
== null )
continue;

if ( (DisplayName =Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services\\" + key).GetValue( "DisplayName"))
== null )
DisplayName = "Unknow";

sb.Append( "Service name=");
sb.Append( key );
sb.Append( " | ");

sb.Append( "DisplayName=");
sb.Append( DisplayName.ToString() );
sb.Append( " | ");

sb.Append( "Service image=");
sb.Append( imagePath.ToString() );

sb.Append( Environment.NewLine );
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<ti******@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Scenario:

I have a service which has been installed in the service component
manager.

I am writing a second program (completely unrelated to the service)
which will run stand alone. I can find all of the services on the
machine with the following line of code:

System.ServiceProcess.ServiceController[] foo =
System.ServiceProcess.ServiceController.GetService s();

My question / problem is:

Is there a way for me to use the information returned by the method
call for an instance of a service (a particular service which I know
the name) to map that back to the pathname for the installed service?

If not, does anyone have any suggestions on a different approach to the
problem???

I am using C# (and accordingly .NET)
Thanks -

Tim Burda

Nov 17 '05 #2
Hi,

I'm not very clear of what you want in the first place, you can use the
registry to get extra info not supplied by the ServiceController class, use
the code below for that. Take a look in the registry and see what other nifo
you need.
string[] st = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services").GetSubKeyNa mes();
StringBuilder sb = new StringBuilder();
foreach( string key in st )
{

object imagePath;
object DisplayName;

if ( (imagePath =Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services\\" + key).GetValue( "ImagePath"))
== null )
continue;

if ( (DisplayName =Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
"System\\CurrentControlSet\\Services\\" + key).GetValue( "DisplayName"))
== null )
DisplayName = "Unknow";

sb.Append( "Service name=");
sb.Append( key );
sb.Append( " | ");

sb.Append( "DisplayName=");
sb.Append( DisplayName.ToString() );
sb.Append( " | ");

sb.Append( "Service image=");
sb.Append( imagePath.ToString() );

sb.Append( Environment.NewLine );
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<ti******@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Scenario:

I have a service which has been installed in the service component
manager.

I am writing a second program (completely unrelated to the service)
which will run stand alone. I can find all of the services on the
machine with the following line of code:

System.ServiceProcess.ServiceController[] foo =
System.ServiceProcess.ServiceController.GetService s();

My question / problem is:

Is there a way for me to use the information returned by the method
call for an instance of a service (a particular service which I know
the name) to map that back to the pathname for the installed service?

If not, does anyone have any suggestions on a different approach to the
problem???

I am using C# (and accordingly .NET)
Thanks -

Tim Burda

Nov 17 '05 #3
Ignacio -

Thanks for your reply. I discovered the registry settings shortly after
my post. But your code snippet was very useful as I hadn't got a chance
to write any code yet. I am looking for the information provided by
imagePath key. I was kind of surprised it was directory available
through properties of the ServiceController object, but the registry
information will work just as well ---- just a little more coding on my
part.

Again, thanks for your help and the code sample.

Tim

Nov 17 '05 #4
Ignacio -

Thanks for your reply. I discovered the registry settings shortly after
my post. But your code snippet was very useful as I hadn't got a chance
to write any code yet. I am looking for the information provided by
imagePath key. I was kind of surprised it was directory available
through properties of the ServiceController object, but the registry
information will work just as well ---- just a little more coding on my
part.

Again, thanks for your help and the code sample.

Tim

Nov 17 '05 #5

<ti******@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Scenario:

I have a service which has been installed in the service component
manager.

I am writing a second program (completely unrelated to the service)
which will run stand alone. I can find all of the services on the
machine with the following line of code:

System.ServiceProcess.ServiceController[] foo =
System.ServiceProcess.ServiceController.GetService s();

My question / problem is:

Is there a way for me to use the information returned by the method
call for an instance of a service (a particular service which I know
the name) to map that back to the pathname for the installed service?

If not, does anyone have any suggestions on a different approach to the
problem???

I am using C# (and accordingly .NET)
Thanks -

Tim Burda


Using System.Management...

string path = ServicePath("event log");
if (path != null) // found?
...


string ServicePath(string serviceName)
{
string ret = null;
ManagementObjectCollection Coll;
using(ManagementObjectSearcher Searcher = new
ManagementObjectSearcher("SELECT PathName from Win32_Service
where DisplayName =" + "\"" + serviceName + "\""))
{
foreach(ManagementObject service in Searcher.Get())
{
ret = service["PathName"].ToString();
}
}
return ret;
}

Willy.
Nov 17 '05 #6

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

Similar topics

1
by: bob | last post by:
I have created a simple Windows service in VB.Net which installs fine using InstallUtil.exe to install it to, for example "c:\test", or "c:\Windows\YellowBanana", but if I install it to "c:\Program...
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
7
by: hufaunder | last post by:
I have a website that uses a web service that is located on the same machine. This webservice calls a program which in return modifies a file in c:\documents and Settings\All Users\Application...
6
by: Jean-Marc Blaise | last post by:
Hi, How can I make MSSQL2K5 setup install everything in the install path I have choosen - it keeps installing some files in ¨%SystemRoot% ? Thanks, JM
2
by: Gregor Horvath | last post by:
Hi, I have a testservice.py (see below). I installed the Windows-Service successfully. (via commandlineoption install) The problem is that it runs only when it is in c:\windows\system32 or in...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
12
by: Anil Gupte | last post by:
I wrote my Windows Service first as a regular Windows Exe because it is easier to debug. In that I used AppDir = Application.ExecutablePath.Substring(0,...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all, my problem is about services. I try comment you all steps for my issue: My development environment: Windows XP SP2
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all, my problem is about services. I try comment you all steps for my issue: My development environment: Windows XP SP2
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.