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.
-
As an unrelated comment: Why in the world would an ASP.NET application look to the computers Env. variables for a file path setting? AppSettings are built-in for that reason alone.– Brent PabstJun 12, 2012 at 16:48
-
Also, this question is off topic for ServerFault, it should be posted on SuperUser– Brent PabstJun 12, 2012 at 16:51
-
1@BrentPabst - The standard temp directory api in .Net reads from it - msdn.microsoft.com/en-us/library/…– George MauerJun 12, 2012 at 18:26
-
Right, so what user is your application running under? Does it change that context each time a user logs in? Typically in IIS this is not the logged in user.– Brent PabstJun 12, 2012 at 22:10
-
@BrentPabst - I don't get what you're getting at. It runs under the same context every time (Network Service). But rather than setting the TMP variable for the entire server, I want to set it just for that user. I think what uSlackr recommends is going to work. Are you proposing another approach?– George MauerJun 13, 2012 at 12:46
1 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'"
-
1Inspired by this answer, I was able to figure out how to do this via Chef. Feb 9, 2015 at 0:12
-
1Is there an elegant way to get the SID of a user?. Particularly a virtual account?. Sep 15, 2015 at 3:01
-
1You could ask that as another question, but if you do a google search for
get sid of application pool identity
, the first result, winterdom.com/2014/05/iis-apppool-identity-sids, has a pretty elegant solution. Sep 25, 2015 at 10:08 -
6@austinian That link is now unavailable. That's why it's important to include such information in an answer itself, instead of linking to it.– StijnDec 21, 2017 at 17:25
-
5This powershell code will grab the SID
$User = New-Object System.Security.Principal.NTAccount("domain", "username") $SID = $User.Translate([System.Security.Principal.SecurityIdentifier]) $SID.Value
orGet-WmiObject win32_useraccount -Filter "name = 'user' AND domain = 'domain'"
– uSlackrDec 22, 2017 at 18:10