Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Environment Variable for Windows Service

I have a batch job that kicks off a windows service

sc serverName start serviceName

I'd like to set an environment variable for that service when I kick it off, similar to how you would do it for a subprocess. How can I do that with a windows service?

To clarify, I don't want to set any global environment variables, just one for that particular process. And I don't have access to the actual Service code.

like image 947
Steve Avatar asked Jul 14 '15 18:07

Steve


1 Answers

I'dont see wich language you use, but assuming you're using C# and your class derived from ServiceBase you have the method

protected override void OnStart(string[] args)

that contains your params in the string array. So starting your service with

sc serverName start serviceName param1 param2

will do the job.

like image 100
VWeber Avatar answered Sep 17 '22 02:09

VWeber