力战者
力战者,天酬之!
#include <windows.h>

//调用GetTokenInformation函数,获取TOKEN_ELEVATION结构体信息,通过结构体中的TokenIsElevated字段就能判断出来
bool IsRunasAdmin(){
    bool bElevated = false;
    HANDLE hToken = NULL;

    // Get current process token
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
        return FALSE;

    TOKEN_ELEVATION tokenEle;
    DWORD dwRetLen = 0;

// Retrieve token elevation information
    if (GetTokenInformation(hToken, TokenElevation, &tokenEle, sizeof(tokenEle), &dwRetLen)){
        if (dwRetLen == sizeof(tokenEle)){
            bElevated = tokenEle.TokenIsElevated;
        }
    }

    CloseHandle(hToken);
    return bElevated;
}            

 

posted on 2019-05-30 20:29  力战者  阅读(631)  评论(0编辑  收藏  举报