利用ShellExecuteEx手动提升用户特权,以管理员权限来运行程序。win7会有UAC弹窗

来源:互联网 发布:哪里能找到工资数据 编辑:程序博客网 时间:2024/04/30 13:37

利用ShellExecuteEx手动提升用户特权,以管理员权限来运行程序。win7会有UAC弹窗

 (2011-07-20 10:30:24)
转载
标签: 

提升用户特权

 

管理员权限

 

it

分类: IT
#include <stdio.h>
#include<windows.h>
#include<tchar.h>

int _tmain(int argc,TCHAR* argv[])
{
SHELLEXECUTEINFO sei={sizeof(SHELLEXECUTEINFO)};
sei.lpVerb=TEXT("runas");
sei.lpFile=TEXT("cmd.exe");//add  application  which you want to run as administrator here
  sei.nShow=SW_SHOWNORMAL;//without this,the windows will be hiden
if(!ShellExecuteEx(&sei)){
DWORD dwStatus=GetLastError();
if(dwStatus==ERROR_CANCELLED){
printf("提升权限被用户拒绝\n");
}
else 
if(dwStatus==ERROR_FILE_NOT_FOUND){
printf("所要执行的文件没有找到\n");
}
}

return 0;
}

通过命令行,也可以自己自动自己的。
0 0
原创粉丝点击