Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if program is running with full administrator rights

I need to determine if my program is running with full administrator rights. By that I mean if uac is turned on (for win vista/7) that I need to determine if the program actually has admin rights (like if the user right clicked and selected "run as administator") and not limited by uac. How do I do this in C++?

like image 622
David Chen Avatar asked Nov 20 '10 00:11

David Chen


People also ask

What is the best way to determine if your program is running with elevated privileges?

Start Task Manager and switch to the Details tab. The new Task Manager has a column called "Elevated" which directly informs you which processes are running as administrator. To enable the Elevated column, right click on any existing column and click Select columns. Check the one called "Elevated", and click OK.

How do you see what apps have admin rights?

Use Your Device's SettingsApps & notifications > Advanced > Special app access > Device admin apps. Security > Device admin apps. Security & privacy > Device admin apps.


1 Answers

  • Win9x: Everyone is "admin"
  • NT4: OpenThreadToken/OpenProcessToken + GetTokenInformation(...,TokenGroups,...) on DOMAIN_ALIAS_RID_ADMINS SID in a loop
  • 2000+: OpenThreadToken/OpenProcessToken + CheckTokenMembership on DOMAIN_ALIAS_RID_ADMINS SID

Other alternatives are: IsUserAnAdmin or AccessCheck

Checking the TOKEN_ELEVATION* stuff in the token is not required for testing the current process but it is useful if you need to find out if the user could elevate because they have a split token etc.

like image 105
Anders Avatar answered Oct 13 '22 22:10

Anders