Windows – What core environment variables should be set for a Windows service

environment-variablesservicewindows

When using a service manager like srvany or nssm to run a normal program as a service, you can set the program's environment using the registry as documented here: http://support.microsoft.com/kb/197178. When doing this, you need to set all the environment variables, not just the ones you want to change. Microsoft's article says, "Make sure to include all core entries like PATH, TEMP, OS, and so on." What exactly is included in "and so on" and is there a definitive reference for that information?

Best Answer

There's no concrete list of exactly which environment variables that you need to set. The answer is simply all the environment variables that your application/service will be using. This varies depending on the application. The particular application might only use TEMP, or it might not need any environment variables at all. Or it might use _NT_SYMBOL_PATH and will crash if that environment variable is not found! There's no way to know without knowing your application.

If you type set at the command-line, you'll be given a list of your current environment variables, which is a pretty good list to start from.

Edit: If you want to see what environment variables your current Windows services are using as an example to go by, Type this into Powershell 3:

$(Get-Process svchost)[0].StartInfo.EnvironmentVariables