User-rights on winnt
-
Hello, exists there an api-function in c++ that i can use to determine the user-rights of the current user logged in in winnt (i need to know if the user has administrator-rights)? Best regards tabor25
KB article Q118626 "HOWTO: Determine Whether a Thread Is Running in User Context of Local Administrator Account" has the answer. Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
-
Hello, exists there an api-function in c++ that i can use to determine the user-rights of the current user logged in in winnt (i need to know if the user has administrator-rights)? Best regards tabor25
There are a whole bunch of functions that you can use to test for permission to perform various activities. Below is a chunk of code from an install tool I was writing. I got fed up and unsed InstallShield once I realised I was being silly reinventing the wheel, but the code pasted worked just fine! Good luck! Iain.;)
if (m_bIsWinnt) { TRUSTEE Trustee; ACCESS_MASK AccessMask; ::BuildTrusteeWithName (&Trustee, "CURRENT_USER"); // Can we edit registry device entries? PSECURITY_DESCRIPTOR pSecDesc= NULL; PACL pAcl = NULL; if (::GetNamedSecurityInfo ( "MACHINE\\SYSTEM\\CurrentControlSet\\Services", SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION, NULL, NULL, &pAcl, NULL, &pSecDesc) == ERROR_SUCCESS) { if (::GetEffectiveRightsFromAcl (pAcl, &Trustee, &AccessMask) == ERROR_SUCCESS) { if (AccessMask & STANDARD_RIGHTS_REQUIRED) m_bIsAdministrator = TRUE; } ::LocalFree (pSecDesc); } // Can we install to Winnt/System32/devices? char buf [MAX_PATH]; if (!GetSystemDirectory (buf, MAX_PATH)) m_bIsAdministrator = FALSE; else ::lstrcat (buf, "\\drivers"); if (m_bIsAdministrator && ::GetNamedSecurityInfo ( buf, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pAcl, NULL, &pSecDesc) == ERROR_SUCCESS) { if (::GetEffectiveRightsFromAcl (pAcl, &Trustee, &AccessMask) == ERROR_SUCCESS) { if (AccessMask & STANDARD_RIGHTS_REQUIRED) m_bIsAdministrator = TRUE; } ::LocalFree (pSecDesc); } else m_bIsAdministrator = FALSE; }
-
Hello, exists there an api-function in c++ that i can use to determine the user-rights of the current user logged in in winnt (i need to know if the user has administrator-rights)? Best regards tabor25
Yes, there is even one simple function in the "Settlement API" as they call it. IsUserAnAdmin()[^]
int x=1, y=5;
x^=y^=x^=y; // whats the content of x and y now?
ClickHereForHelp();