0

We have a custom script that allows us to reset computers that are sent out which the computers are locked down so we have to run the program as an Administrator (elevated user). The goal is to delete a directory in the current users AppData\Local directory but when I get the path with the below code, its that of the elevated user that authorized the app to run. Anyway to get logged in user path instead?

string strDirectory = 
   Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

Regular User: c:\Users\bob\AppData\Local\

Running As Administrator: c:\Users\Administrator\AppData\Local\

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Brad Wickwire
  • 1,093
  • 4
  • 16
  • 29
  • Possible duplicate [how to find MyMusic Folder from other users?](http://stackoverflow.com/questions/3493607/how-to-find-mymusic-folder-from-other-users) – Dustin Kingen May 02 '17 at 20:58
  • Try looking into System.Security.Principal.WindowsIdentity.GetCurrent().Name; then you can manually put the local app directory string together, assuming the default locations have not been modified. – Sorceri May 02 '17 at 21:07
  • I tried to run this on my computer and it returns ComputerName\UserName plus when I run on one of our systems (not as an elevated user) Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) returns "c:\Users\stubw\AppData\Local" and System.Security.Principal.WindowsIdentity.GetCurrent().Name returns ComputerName\Box Office – Brad Wickwire May 04 '17 at 15:33

0 Answers0