如何提升程序权限

如何自己给程序提升权限:

BOOL EnablePrivilege(LPCSTR lpName, BOOL fEnable)
{
        HANDLE hObject;
        LUID Luid;
        TOKEN_PRIVILEGES NewStatus;

        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hObject))
                return FALSE;

        if (LookupPrivilegeValue(NULL, lpName, &Luid))
        {
                NewStatus.Privileges[0].Luid = Luid;
                NewStatus.PrivilegeCount = 1;
                NewStatus.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0;

                AdjustTokenPrivileges(hObject, FALSE, &NewStatus, 0, 0, 0);
                
                CloseHandle(hObject);
                return TRUE;
        }
        
        return FALSE;
}

//调用方式 EnablePrivilege(SE_DEBUG_NAME,TRUE);


你可能感兴趣的:(如何提升程序权限)