8

How can I check if a process has elevated privileges in Windows 7 (using native C++, not C#/C++.net) ?

I've been looking for an answer for quite sometimes, but all I can find are the answers that use the .NET framework.

Ajay
  • 18,086
  • 12
  • 59
  • 105
TCS
  • 5,790
  • 5
  • 54
  • 86

1 Answers1

8

The simplest approach is to call the IsUserAnAdmin function. If you need more precision you can also use GetTokenInformation but in most cases that is overkill.

Kenny Kerr
  • 3,015
  • 15
  • 18
  • 2
    Kenny is right and this is easy to test. Write an app that prints out whether you are an admin or not and run it elevated and not, signed in as admin and a regular user (who will need OTS to elevate). You will see in four quick runs that you are reported to be an admin iff the app is elevated, regardless of who first signed into the machine. – Kate Gregory Nov 16 '10 at 21:36
  • FWIW, the latest recommendation on the MSDN article is to use CheckTokenMembership. _This function is a wrapper for CheckTokenMembership. It is recommended to call that function directly to determine Administrator group status rather than calling IsUserAnAdmin._ – susmits Jul 27 '15 at 07:55
  • 1
    @KateGregory Thank you for explaining this so simply; the MSDN documentation implies that it checks the privileges of the owner user (is owner admin or not), but as you explain that is not correct. – wizzwizz4 Jul 01 '16 at 19:06