Win Service running under LocalService account cannot access environment variables

I am looking for prove or disprove of my theory. We have windows service which runs under LocalSystem account. the service is calling msbuild and builds csproj (Visual Studio project) file, which use Environment variable. But its falling as it cant recognize or find that environment variable.

Is there way how I can test or assure that win service running under LocalSystem has access to environment variables?


If your environment variables are changing and you're running the service (as LocalSystem) in Windows Server 2003, XP, or 2000 then you might be running into the case that you need to restart the machine in order for the service manager to reread the environment. See this KB article for more info.

There's a hotfix available for Windows Server 2003 that will resolve this.


Programs running as SYSTEM (LocalSystem, NT_AUTHORITY\SYSTEM) will have an environment built from the variables specified at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and at HKEY_USERS\.DEFAULT\Environment. Make sure the variables you want it to "see" are defined in one of those locations and they will be accessible.