Skip to content

Instantly share code, notes, and snippets.

@childnode
Last active August 29, 2015 14:10
Show Gist options
  • Save childnode/f5f2583f92d515eb97e6 to your computer and use it in GitHub Desktop.
Save childnode/f5f2583f92d515eb97e6 to your computer and use it in GitHub Desktop.
Get correct %LOCALAPPDATA% for SYSTEM user on a win64 system. http://ss64.com/nt/syntax-variables.html
Set IsSystemUser=0
If "%USERNAME%" == "SYSTEM" Set IsSystemUser=1
If "%COMPUTERNAME%$" == "%USERNAME%" Set IsSystemUser=1
If %IsSystemUser% EQU 1 (
echo "running as system user %USERNAME%";
If NOT %PROCESSOR_ARCHITECTURE% == x86 (
echo "64bit system, looking for WOW64"
IF EXIST %SYSTEMROOT%\SysWOW64\config\systemprofile\AppData\Local\NUL (
Set LOCALAPPDATA="%SYSTEMROOT%\SysWOW64\config\systemprofile\AppData\Local"
) else (
echo "WARNING C:\Windows\SysWOW64\config\systemprofile\AppData\Local is not readable:"
dir %SYSTEMROOT%\SysWOW64\config\systemprofile\AppData\Local
echo "Still using %LOCALAPPDATA%"
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment