3

How would I obtain the logged on user SID in an elevated .NET application?

I have tried WindowsIdentity.GetCurrent() which of course returns the administrator that elevated the process. From what I can see I may need to use native methods to do this, could anyone provide a more elegant way?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Luke
  • 291
  • 2
  • 8
  • Is this on a server? If it is this might be helpful: http://stackoverflow.com/questions/5230441/how-to-get-at-the-current-users-windows-identity – FrostyFire Feb 16 '13 at 23:31
  • You could grab it from the Registry. Then compare the keys – Greg Feb 17 '13 at 00:50

1 Answers1

1

Investigating Greg's suggestion of using the registry:

I have found the following key which appears reliable in providing the currently logged on user's information. This key includes information such as display name and SID. This information is stored under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI"

This information is accurate on Windows 8. I have checked Windows 7 and much less information is included, eg: there is no logged on user SID.

Community
  • 1
  • 1
Luke
  • 291
  • 2
  • 8
  • You can run a elevated command prompt process that can query it for you as well. Which you can pipe to a document and extract for usage. – Greg Feb 17 '13 at 12:30