I have a C CGI that is invoked by Apache, both running as SYSTEM.
The CGI relies on the setting of WINDIR and TEMPLATES environment variables. It gets the value of WINDIR without any problems but getenv("TEMPLATES") always returns NULL.
TEMPLATES is a system variable.
Another post Win Service running under LocalService account cannot access environment variables suggested rebooting, I tried this to no avail, and to make sure HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ has the needed environment variable, it does.