C++ 提权

BOOL EnableDebugPrivilege() {
    HANDLE hToken;
    BOOL fOk = FALSE;
    if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)) {
        TOKEN_PRIVILEGES tp;
        tp.PrivilegeCount = 1;
        LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);

        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);

        fOk = (GetLastError() == ERROR_SUCCESS);
        CloseHandle(hToken);
    }
    return fOk;
}

调用:

 	if (EnableDebugPrivilege()) {
      MessageBox(NULL,L"EnableDebugPrivilege success.",L"",NULL);
	}
	else {
      MessageBox(NULL, L"EnableDebugPrivilege failed.", L"", NULL);
	}

你可能感兴趣的:(C++功能函数)