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 Pabst– Brent Pabst2012-06-12 16:48:46 +00:00Commented Jun 12, 2012 at 16:48
- Also, this question is off topic for ServerFault, it should be posted on SuperUserBrent Pabst– Brent Pabst2012-06-12 16:51:04 +00:00Commented Jun 12, 2012 at 16:51
- 1@BrentPabst - The standard temp directory api in .Net reads from it - msdn.microsoft.com/en-us/library/…George Mauer– George Mauer2012-06-12 18:26:35 +00:00Commented Jun 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 Pabst– Brent Pabst2012-06-12 22:10:10 +00:00Commented Jun 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 Mauer– George Mauer2012-06-13 12:46:56 +00:00Commented Jun 13, 2012 at 12:46
| Show 1 more comment
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.Kenny Evitt– Kenny Evitt2015-02-09 00:12:26 +00:00Commented Feb 9, 2015 at 0:12
- 1Is there an elegant way to get the SID of a user?. Particularly a virtual account?.Beau Trepp– Beau Trepp2015-09-15 03:01:10 +00:00Commented 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.austinian– austinian2015-09-25 10:08:55 +00:00Commented 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.Stijn– Stijn2017-12-21 17:25:33 +00:00Commented Dec 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.ValueorGet-WmiObject win32_useraccount -Filter "name = 'user' AND domain = 'domain'"uSlackr– uSlackr2017-12-22 18:10:33 +00:00Commented Dec 22, 2017 at 18:10