Logon SIDToday I was reusing some old (pre vista) code the retrieves the Logon SID that I wrote a few years ago. The Logon SID is a special SID that identifies a logon session that has the form S-1-5-5-X-Y.

You can view your Logon SID with Process Explorer, right click a GUI process, select Properties and goto the Security Tab:

Process Explorer|Security Tab|Logon SID

 

My code called OpenWindowStation and then passed the obtained handle to GetUserObjectInformation with the UOI_USER_SID index (error handling left out):

Windows 7 LogoOn my Windows 7 machine the call to GetUserObjectInformation failed however. GetLastError returns ERROR_ACCESS_DENIED (error 5) with description Access is denied.

The handle returned from OpenWindowStation was valid so I assumed that the ACCESS_MASK was the problem. I replaced READ_CONTROL with WINSTA_READATTRIBUTES and then it worked fine: