利用ShellExecuteEx手动提升用户特权,以管理员权限来运行程序

#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;

}

以一个非管理员权限的程序运行   其它程序,提升权限     

a call   b    b call c     a开机启动      a不能具有管理员权限  a call b的时候就要提升权限了!

猜你喜欢

转载自blog.csdn.net/yousss/article/details/84762946