Detect if running with administrator privileges under Windows XP
This will detect if the user is running in elevated mode (eg a command prompt that was "Run As" Administrator). It relies on the fact that you require admin privileges to read the LOCAL SERVICE account reg key:
reg query "HKU\S-1-5-19"
this will return a non-zero error code if it cannot be read, and zero if it can.
Works from XP up...
If you run
>net localgroup administrators
in a command shell you should get the list of administrator accounts in Windows XP. Simply parse and scan the output to check for the particular user account you want. For e.g. to check if the current user is an administrator you could do -
>net localgroup administrators | find "%USERNAME%"
Piskvor option its fine, or check this urlhttp://weseetips.com/2008/04/16/how-to-check-whether-current-user-have-administrator-privilege/
this is the code in that page
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;PSID AdministratorsGroup;// Initialize SID.if( !AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup)){ // Initializing SID Failed. return false;}// Check whether the token is present in admin group.BOOL IsInAdminGroup = FALSE;if( !CheckTokenMembership( NULL, AdministratorsGroup, &IsInAdminGroup )){ // Error occurred. IsInAdminGroup = FALSE;}// Free SID and return.FreeSid(AdministratorsGroup);return IsInAdminGroup;