Windows How to check if a command prompt has admin rights.

The command whoami in windows return the list of groups the current user belongs to.

Syntax:

whoami /groups | findstr /b BUILTIN\Administrators

The list of groups returned by whoami can be filtered on the String Administrators. If the user belong to that group the group will be returned with "Enabled group". If the user is not an administrator, the group is not returned or it is returned with "Group used for deny only".

Example:

The command is run from a command prompts that has Administrator rights:

C:\WINDOWS\system32>whoami /groups | findstr /b BUILTIN\Administrators
BUILTIN\Administrators                                        Alias            S-1-5-32-544                                  Mandatory group, Enabled by default, Enabled group, Group owner

C:\WINDOWS\system32>

The command is run from a command prompts that does not have Administrator rights:

C:\Users\Olivier>whoami /groups | findstr /b BUILTIN\Administrators
BUILTIN\Administrators                                        Alias            S-1-5-32-544                                  Group used for deny only

C:\Users\Olivier>


References:

Windows whoami

Recent Comments