Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:13:38+00:00 2026-06-01T06:13:38+00:00

I need to get the AuthenticationID as returned by GetTokenInformation with the TokenStatistics class

  • 0

I need to get the AuthenticationID as returned by GetTokenInformation with the TokenStatistics class for the user that logged in on the station whether I’m elevated or not.

Lemme give you some more info. Suppose I do :

var Result = GetTokenInformation(WindowsIdentity.GetCurrent().Token, TOKEN_INFORMATION_CLASS.TokenStatistics, TokenInformation, TokenInfLength, out TokenInfLength);

This will allow me to get the AuthenticationID from the TokenInformation structure without problem. Let’s say the resulting authenticationID is “00000000-00001234”

Now if I right click Visual Studio and click “Run as administrator”, launch my code a second time, the result will be something else, for example “00000000-00001289”. But I need “00000000-00001234”

How can I get “00000000-00001234” whether the current process is elevated or not ?

I suppose it’s just a matter of finding the right Token to give to GetTokenInformation, but I’m running in circles here …

Note : I based my code on How to get the logon SID in C# to implement GetTokenInformation and then adapted it to be able to get TokenStatistics.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:13:40+00:00Added an answer on June 1, 2026 at 6:13 am

    OK, I finally got it to work. These are the steps (not posting the full code, it’s quite long) :

    1. Use WMI (ManagementObject) on the win32_process class + the managed Process class recursively to create the current process’ ancestry
    2. In my particular case I stop the algorithm when I find the “explorer” process or when I hit an exception, as it’s very likely that explorer is not elevated.
    3. P/Invoke the OpenProcessToken function from advapi32.dll on the ProcessId returned by step 2. This gets you a userToken that can be used to construct a new WindowsIdentity that you can use in step 4
    4. You can then feed that WindowsIdentity Token property to GetTokenInformation to get back your AuthenticationID.

    This is tested and working.

    Reference :

    • GetTokenInformation : How to get the logon SID in C# (change the function to call TokenStatistics)
    • Get parent of process : http://bytes.com/topic/c-sharp/answers/255642-enumerataing-processes-c
    • Get WindowsIdentity of a process : http://dotbay.blogspot.fr/2009/06/finding-owner-of-process-in-c.html

    If you see any problem with this procedure don’t hesitate to comment or post your own answer !


    Note : there is a problem if one of the parent process has been killed : WMI will give you the id of a process that does not exist anymore. The nature of the product I’m working has me rebooting explorer from time to time (only during dev), this is how I saw the problem. It’s not really an issue for me, but good to know.

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WMI, I need to get some information, but when class is not
Need to get an div with overflow:hidden; not to wrap its children. I need
I am using forms authentication and need to get a list of users that
I need to get know how SiteMapProvider.IsAccessibleToUser() works. Built-in XmlSiteMapProvider calls HttpContext.User.IsInRole() which uses
I need to get the current logged on username? I need this to work
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I have two tables with a weak relation. I need get a text value
Need to get the 10 word before and 10 words after for the given
I need to get all the objects whose id matches a specific pattern .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.