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.
Asked
Active
Viewed 6.4k times
30
Stijn
- 218
George Mauer
- 499
1 Answers
34
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'"
uSlackr
- 6,452