1.要求以管理员身份运行
在vs工程属性中,Linker ---> Manifest File---> UAC Execution Level,选择requireAdministrator (/level=‘requireAdministrator‘)选项
BOOL WINAPI EnablePrivileges() { HANDLE hToken; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return( FALSE ); LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); if (GetLastError() != ERROR_SUCCESS) return FALSE; return TRUE; }
为编写的Windows程序提升权限,布布扣,bubuko.com
原文:http://blog.csdn.net/tobacco5648/article/details/26454851