swsbuyer
asked on
How to pass command line arguments to Windows Service
I am writing a service in C#. It needs to take couple of command line arguments. If I add these to the "Start Parameters" within the service properties, then I cannot save those. Is there another way to pass arbitrary command line arguments to the services. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The OnStart() can take a string array of arguments just like a simple command console app. anything you put in the startup parameters will be your array of string arguments
ASKER
My question was "how do I save the startup parameters". Within the Windows service properties, this field is not saved. If you know the answer, please definitely let me know.
ASKER
Along with the solution recommended by Michael D, another option would be to build the installer within the app itself - to programatically install the service. Please see http://www.c-sharpcorner.com/UploadFile/sachin.nigam/InstallingWinServiceProgrammatically11262005061332AM/InstallingWinServiceProgrammatically.aspx.