Reputation: 2968
We have a windows service application. When we install the service, we pass in command line arguments to capture some values that are used by the service. As an example, here -r is used to identify that it is an install.
MyService.exe -r /url=value1 /time=value2
These values are stored in the local registry.
Now we want these values to be configurable. i.e, when we stop and start the service, we should be able to do something like (-s to identify start of the service)
MyService.exe -s /time=newvalue
Now, is it possible to read this new value from the command line?.
Upvotes: 1
Views: 2470
Reputation: 10849
There are two types of arguments for windows services :
Process Explorer
.SC START [arguments]
. arguments passed in the method is different from "command line process arguments". So arguments passed in SC start
is only known by the service itself.Upvotes: 1
Reputation: 6738
Assuming that your entry point for the EXE looks something like
static void Main(string[] args)
You can just use the args
array which has all the command line arguments as an array.
If you don't/can't get it in the entry point, you can use
string[] args = Environment.GetCommandLineArgs();
to get the command line arguments.
Upvotes: 3