Have Service Inherit Environment Variables from Command Prompt Window


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?
Aug 3, 2011
Reaction score
You have to use
instead of
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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question