473,811 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ServiceP rocess.ServiceC ontroller[] foo =
System.ServiceP rocess.ServiceC ontroller.GetSe rvices();

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 13541
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 ServiceControll er 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.Local Machine.OpenSub Key(
"System\\Curren tControlSet\\Se rvices").GetSub KeyNames();
StringBuilder sb = new StringBuilder() ;
foreach( string key in st )
{

object imagePath;
object DisplayName;

if ( (imagePath =Microsoft.Win3 2.Registry.Loca lMachine.OpenSu bKey(
"System\\Curren tControlSet\\Se rvices\\" + key).GetValue( "ImagePath" ))
== null )
continue;

if ( (DisplayName =Microsoft.Win3 2.Registry.Loca lMachine.OpenSu bKey(
"System\\Curren tControlSet\\Se rvices\\" + key).GetValue( "DisplayNam e"))
== null )
DisplayName = "Unknow";

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

sb.Append( "DisplayName=") ;
sb.Append( DisplayName.ToS tring() );
sb.Append( " | ");

sb.Append( "Service image=");
sb.Append( imagePath.ToStr ing() );

sb.Append( Environment.New Line );
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<ti******@hotma il.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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.ServiceP rocess.ServiceC ontroller[] foo =
System.ServiceP rocess.ServiceC ontroller.GetSe rvices();

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 ServiceControll er 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.Local Machine.OpenSub Key(
"System\\Curren tControlSet\\Se rvices").GetSub KeyNames();
StringBuilder sb = new StringBuilder() ;
foreach( string key in st )
{

object imagePath;
object DisplayName;

if ( (imagePath =Microsoft.Win3 2.Registry.Loca lMachine.OpenSu bKey(
"System\\Curren tControlSet\\Se rvices\\" + key).GetValue( "ImagePath" ))
== null )
continue;

if ( (DisplayName =Microsoft.Win3 2.Registry.Loca lMachine.OpenSu bKey(
"System\\Curren tControlSet\\Se rvices\\" + key).GetValue( "DisplayNam e"))
== null )
DisplayName = "Unknow";

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

sb.Append( "DisplayName=") ;
sb.Append( DisplayName.ToS tring() );
sb.Append( " | ");

sb.Append( "Service image=");
sb.Append( imagePath.ToStr ing() );

sb.Append( Environment.New Line );
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<ti******@hotma il.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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.ServiceP rocess.ServiceC ontroller[] foo =
System.ServiceP rocess.ServiceC ontroller.GetSe rvices();

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 ServiceControll er 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 ServiceControll er 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******@hotma il.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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.ServiceP rocess.ServiceC ontroller[] foo =
System.ServiceP rocess.ServiceC ontroller.GetSe rvices();

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.Manageme nt...

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


string ServicePath(str ing serviceName)
{
string ret = null;
ManagementObjec tCollection Coll;
using(Managemen tObjectSearcher Searcher = new
ManagementObjec tSearcher("SELE CT PathName from Win32_Service
where DisplayName =" + "\"" + serviceName + "\""))
{
foreach(Managem entObject 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
3291
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 Files\Test" it installs ok but will not start (no useful error message is given other than the usual annoying suggestion about having sufficient privileges). The problem only seems to happen with spaces, not long filenames. I have found a...
3
57011
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 want to test this service on a Windows Server 2003 box that doesn't have the Visual Studio Command prompt. How do I go about installing the service on the Windows Server 2003 box? Thanks!
7
19743
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 Data\...'. Unfortunately, whenever the webservice is executed I get the following error message: Access to the path 'C:\Documents and Settings\All Users\Application Data\...' is denied. Permissions for the default website (where the website and...
6
2165
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
4412
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 the python path. I added the desired path (Y:\) to the PYTHONPATH environment variable for the system account and rebooted. When I start command line python and do a import testservice everything is fine.
11
26648
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 and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my server shows the c: \php5\pear path. I can't change it no matter what I do I also tried the...
12
3722
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, Application.ExecutablePath.LastIndexOf("\")) ' Where this application Excutable sits Now, when I am converting it to a Service, what path can I use? Or can I specify a path in the service to always use as a data path? I would prefer the former because I do not know the layout of...
0
2880
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
6005
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
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10652
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10395
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10408
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5561
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.