How does one retrieve the Windows Logon SID in C# .net? (not the user SID, but the unique new one for each session)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m afraid you have to resort to using P/Invoke. There’s an example how to do it at pinvoke.net (please see the bottom of the page):
Please note that I changed the example by altering just one line, I replaced
TOKEN_INFORMATION_CLASS.TokenUserwithTOKEN_INFORMATION_CLASS.TokenSessionIdwhich is exactly what you need.Hope this helps.
Update: Here’s the working (at least on my machine) code:
N.B. I tested it on my x64 machine, so please pay close attention on
TokenInformation.ToInt64()piece of code, maybe you should replace it withTokenInformation.ToInt32()