Have Service Inherit Environment Variables from Command Prompt Window

  • Thread starter Thread starter Sean Dockery
  • Start date Start date
S

Sean Dockery

Hello everyone.

I am attempting start a service and have it respect environment variable
changes that I have made in the current Command Prompt window's environment.
Basically, I want to do this...

C:\> set FOO=BAR
C:\> net start MYSERVICE

....and have MYSERVICE see FOO=BAR in its environment variables.

I used Process Explorer to examine the Properties of the MYSERVICE service
and found that its environment variables did not include my (modified) FOO
environment variable.

How might this be accomplished?
 
You have to use
setx
instead of
set
because setx modify the registry and the service gets his environment from registry.
For removing of environment variable from registry you can use "reg delete HKCU\Environment /v".


try this:

c:\> setx FOO=BAR
c:\> net start MYSERVICE
c:\> REG delete HKCU\Environment /V FOO /F
 
Back
Top