Discussion:
Have Service Inherit Environment Variables from Command Prompt Window
(too old to reply)
Sean Dockery
2008-03-12 21:36:04 UTC
Permalink
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?
Georg Thor
2011-08-03 08:20:48 UTC
Permalink
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:

c:\> setx FOO=BAR
c:\> net start MYSERVICE
c:\> REG delete HKCU\Environment /V FOO /F
Post by 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?
Georg Thor
2011-08-03 08:27:36 UTC
Permalink
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
Post by 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?
Post by Georg Thor
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".
c:\> setx FOO=BAR
c:\> net start MYSERVICE
c:\> REG delete HKCU\Environment /V FOO /F
Georg Thor
2011-08-03 08:28:20 UTC
Permalink
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
Post by 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?
Post by Georg Thor
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".
c:\> setx FOO=BAR
c:\> net start MYSERVICE
c:\> REG delete HKCU\Environment /V FOO /F
Post by Georg Thor
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".
c:\> setx FOO=BAR
c:\> net start MYSERVICE
c:\> REG delete HKCU\Environment /V FOO /F
Loading...