Determine if the program is running under Administrator privileges

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.