|
-
Dec 2nd, 2005, 07:27 AM
#1
Thread Starter
Hyperactive Member
best way to pass info to a service
Hi,
I have written a service in c# and have go it working to the best of my ability.
Within my code I have a load of things that are possibly changeable in the future, so rather than hardcode within the program I have held this information within an xml "config" file. I can just change this file and restart the service and off it goes using the new parameters (I load the file on the OnStart event and load the data into the right fields within...etc.)
I have called my file config.xml and when I install the service, the home directory for it is windows\system32 - I therefore have to place my file here (I can hardcode it to say c:\ or some other dir)
what I would like is full flexability to specify the location, Ideally doing something like this
VB Code:
net start mydotnetservice -config_file=c:\mydir\config.xml
I would like to pass into the service the location of its config file to use
I have tried the following
on the Main() i tried adding this string[] args
eg
VB Code:
static void Main(string[] args)
then using args[0].ToString();but nothing
also have again tried
but again args[0].ToString(); is null.
is it possible to pass anything into a service using the net start command. otherwise I'm forced to hold my file in a known location or so something like use a know location in the reg that points to the file (somthing im not keen on)
any thoughts appreciated,
cheers AJP
Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor
Real programmers use less....
-
Dec 2nd, 2005, 11:46 AM
#2
Re: best way to pass info to a service
You could modify your code to use a custom XML file with your values in it. It'd use an XMLReader for example. This'd allow you to pass in the parameters such as location of the file.
Granted, it'd take a considerable amount of extra coding to get it done.
-
Dec 2nd, 2005, 02:29 PM
#3
Re: best way to pass info to a service
Hmm, I'm not sure with a service, but with a standard app, you can call Environment.GetCommandLineArgs() which returns a string array of the command line parameters.
Bill
-
Dec 5th, 2005, 08:30 AM
#4
Thread Starter
Hyperactive Member
Re: best way to pass info to a service
hi
thanks for the comments
I used Environment.GetCommandLineArgs() to dump the command line and got
"c:\...etc..\windowsservice1\bin\debug\windowsservice1.exe"
which is what I guess is eventually happening with me "net start"ing it.
I think that I am asking for something not do-able - them program net.exe would have to take any parameter and pass this thru to the actual service program (as a parmeter list) and is just not designed to do that.
thanks anyway,
cheers AJP
Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor
Real programmers use less....
-
Dec 6th, 2005, 10:16 PM
#5
Hyperactive Member
Re: best way to pass info to a service
I don't think you can pass parameters in. But you can read your configuration file from the application directory instead of a hard coded directory.
There IS a way to do advanced communication with services, but you are going to have to use Remoting. That's beyond my knowledge at this point however.
-
Dec 6th, 2005, 10:53 PM
#6
Re: best way to pass info to a service
If you go into the services Console, you can open a services properties, and if it is stopped, specify commandline parameters. Can you see them with Environment.GetCommandLineArgs that way?
If this is the case, then you should be able to configure an installer to set up the service with your needed parameters, but I'm not sure how to go about it if they need to change frequently.
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|