#include <stdio.h>
#include<windows.h>
#include<tchar.h>
int main(void)
{
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");
}
}
getchar();
getchar();
return 0;
}
ShellExecute使用管理员身份执行
最新推荐文章于 2024-06-17 07:56:12 发布