Windows – How to set environment variable for another user

environment-variableswindows

On Windows, how do I set an environment variable for a user other than the currently logged in one? I need to set the TMP variable to change the temporary directory used by an ASP.NET app.

Best Answer

You can access through the registry. Modify the \Environment\Tmp key in HKEY_Users\<their SID>

Here are two solutions for getting the account SID

$User = New-Object System.Security.Principal.NTAccount("domainname", "username") 
$SID = $User.Translate([System.Security.Principal.SecurityIdentifier]) 
$SID.Value 

or

Get-WmiObject win32_useraccount -Filter "name = 'username' AND domain = 'domainname'"