473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passiing command line arguments to a service

MW
Hi all,

I want to pass arguments to my OnStart(args) method in a windows service
application.

I tested this out by
NET START myService /test

and it works fine. I however want to give my users the ability to use the
Start button from the Service Control Manager instead of typing NET START or
executing a batch file to the same affect.

To achieve this I thought about editing the registry where the location of
the service exe might be stored. I tried editing the ImagePath property of
the service but that did not work. OnStart did not recieve the arguments.
Incidently thats how Tomcat passes arguments to its service.

I cannot use configuration files or add my own registry settings for this
service and I am restricted to passing the argument. Any comments will be
most welcome.

Many thanks,
-Mujahid
Jul 21 '05 #1
4 3514
MW
Found a solution for this. Thanks

"MW" <mw*********@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I want to pass arguments to my OnStart(args) method in a windows service
application.

I tested this out by
NET START myService /test

and it works fine. I however want to give my users the ability to use the
Start button from the Service Control Manager instead of typing NET START or executing a batch file to the same affect.

To achieve this I thought about editing the registry where the location of
the service exe might be stored. I tried editing the ImagePath property of
the service but that did not work. OnStart did not recieve the arguments.
Incidently thats how Tomcat passes arguments to its service.

I cannot use configuration files or add my own registry settings for this
service and I am restricted to passing the argument. Any comments will be
most welcome.

Many thanks,
-Mujahid

Jul 21 '05 #2
I'm having the same problem, could post up a solution please.

"MW" <mw*********@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Found a solution for this. Thanks

"MW" <mw*********@hotmail.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I want to pass arguments to my OnStart(args) method in a windows service
application.

I tested this out by
NET START myService /test

and it works fine. I however want to give my users the ability to use the Start button from the Service Control Manager instead of typing NET START
or
executing a batch file to the same affect.

To achieve this I thought about editing the registry where the location

of the service exe might be stored. I tried editing the ImagePath property of the service but that did not work. OnStart did not recieve the arguments. Incidently thats how Tomcat passes arguments to its service.

I cannot use configuration files or add my own registry settings for this service and I am restricted to passing the argument. Any comments will be most welcome.

Many thanks,
-Mujahid


Jul 21 '05 #3
Hi John and Stephen,

When I added arguments to the SYSTEM\CurrentControlSet\Services\[My service
name]\ImagePath I found that its not the OnStart() event that recieves the
arguments but the Main function of the service class.

You can do two things
- Write another constructor that uses the arguments. Since an instance of
the service class is created in the main function, the value will be passed
or
- Expose a property that can be set after the service class has been
instatiated

I wanted to create multiple instances of my service each running in their
own process, pass the service name as an argument, based on which I could
look up the relevant registry and configuration files.
I posted my solution to another newsgroup. Here is the url to that thread.

http://www.dotnetsmart.com/DesktopDe...st&PostID=5698

HTH


Jul 21 '05 #4
Thanks,

For some reason never even thought about the main function, probably because
VS .net creates the OnStart method with the args parameter and provides
absolutely no documentation about when it will be set.

I now store the args supplied to the main function, then combine it with the
args supplied to the Onstart method and everything is working great.

Cheers!
Jul 21 '05 #5

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

Similar topics

5
by: Eric Chong | last post by:
I created a Windows Service in C# that requires to get passed command arguments like a Console App. I noticed that there is an option "Start parameters" text box in the property of a Windows...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
3
by: Shailesh Humbad | last post by:
I want to set a command-line argument for a Windows service that I programmed in VB.Net. This ought to be available from the service installer classes, but I can not find any such property. What...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
5
by: MW | last post by:
Hi all, I want to pass arguments to my OnStart(args) method in a windows service application. I tested this out by NET START myService /test and it works fine. I however want to give my...
3
by: =?Utf-8?B?Um9iZXJ0IFNsYW5leQ==?= | last post by:
I'm trying to install a .NET Windows Service using the ServiceInstaller / ServiceProcessInstaller classes. I cannot seem to find a way to specify command line arguments. I've looked through...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
4
by: tvrdak | last post by:
Hello, I would like to register service to start with some arguments - meaning command line arguments of service itself. The best approach was some articles about selfregistrating service, like...
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.