How to determine whether the program runs as admin

You may wonder which account is your program running under, and following code might help:

BOOL bIsSystem = FALSE;
BOOL bIsFullAdmin = FALSE;

CAccessToken token;

    CSid sid;
        bIsSystem = (sid == Sids::System());

    CTokenGroups groups;
        DWORD dwAttrs = 0;
        if((groups.LookupSid(Sids::Admins(), &dwAttrs)))
            bIsFullAdmin = !(dwAttrs & SE_GROUP_USE_FOR_DENY_ONLY);


Posted on April 18, 2011, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: