1. Two concepts are presented (the condition is that the system is a later version of Vista because UAC was introduced)
- One is to run the program account is the Administrator account
- The other is that the current operating environment is an administrator environment
2. Judging whether the program is running on administrator's rights, directly using the function isuseranadmin can be judged
#include <ShlObj.h> #include <tchar.h>int _tmain () {BOOL bisadmin = Isuseranadmin (); if (bisadmin) _tprintf_s (_t ("Run as Administrator")); else_tprintf_s (_t ("Run as user"); System ("pause"); return 0;}
3. Test run
(1) Administrator account login System
_1. Running the program directly
To view the properties of a process by using Processes Explorer
The user is found to be the Administrator account (wind) at this time, in the user group list, there is the Administrator user Group (Administrators), but the flags is deny, this is due to UAC control, the Administrator account log on the system run by default under the standard user rights.
_2.run as Administrator
To view the properties of a process by using Processes Explorer
Found at this time the Users property is the Administrator account (wind), the Administrator user Group (Administrators) of the flags is owner
(2) Standard User Login system
_1. Direct operation
To view process properties by using Processes Explorer
found that the user running at this time is test (normal user), there is no administrator user group in the user group
_2.run as Administrator
To view process properties by using Processes Explorer
The user attribute is found to be an Administrator account (wind), and the group list has an administrator user, where flags is owner
4. By running the test can know, to determine whether to run under administrator rights, there are two conditions
- Process running user as Administrator account
- The flags for the Administrator user group are owner
5. So you can write your own isuseranadmin function
Refer to the Am_i_in_admin_group function in http://www.cnblogs.com/cpointer/p/4138574.html
Personally feel that this function can determine whether the process is running the user is the Administrator user group, but also can determine whether to run permissions for administrators.
Determine if the program is running under Administrator privileges