绕过UAC以管理员身份启动程序

绕过UAC以管理员身份启动程序

写这篇文章主要是看到了:http://www.7tutorials.com/use-task-scheduler-launch-programs-without-uac-prompts文章中所用到的方法,于是想记录下来

UAC不用多说,往往我们要用管理员身份去运行一个程序的时候,总是要有一个提示框:


可能会有用户选择禁用UAC,但这毕竟对系统的安全存在影响。下面就用一个简单的方法解决这个问题。该方法就是利用系统自带的任务计划程序来实现的。

一、创建一个任务来运行你所要运行的程序

找到任务计划程序。

方式一、开始菜单->附件->系统工具->任务计划程序;

方式二、直接在开始菜单的搜索栏中输入“任务计划程序”也可以找到;

方式三、运行(win+r)输入“taskschd.msc”。

通过以上三种方式中的一种都可以打开任务计划程序,那么下面就是添加任务了。在任务计划程序的右上角的操作里面单击“创建任务...”



出现如下窗口,按照图示配置好要描述和权限:


这里的注意点我已经标记出来了。

说明

第一点:名称可以随意写,但不能与你已有的名称重复;

第二点:勾选使用最高权限运行,因为我们是想用管理员权限来运行一个程序,所以要用高权限,至少管理员权限;

第三点:配置中选择与你机器环境相适应的配置,否则程序运行可能会出问题。

添加好这些基本配置以后,我们要选择用管理员权限来运行哪个程序,这里我演示运行CMD。(我记得在我之前的博文谈到过“如何在CMD下运用管理员权限”,链接:http://blog.csdn.net/zyw_anquan/article/details/7756499)在刚才那个创建任务的界面的第三个选项卡中,添加操作:


红线标出的部分,第一处是你所要执行的操作,第二处是你要执行的程序(exe、com、bat等)所在位置。填好以后确定,至此整个任务计划已经默认地完整配好了,但是你要确定在设置选项卡里面的配置如下(通常默认就是下图所示):


即,你要允许系统运行该任务,第二点,要确定该任务是否会启动新实例。如果你要想更改一些时间或者其他操作可以继续自己添加,这里不赘述了。如果一些按照上述配置做好,确定以后就会出现如下界面:


右键运行该任务,你会看到以管理员身份运行出来的cmd,且没有UAC的提示。


好了,到这里我们就完成了成功绕过UAC来运行某个实例程序了。但是这很不方便,我们如果要运行该程序需要每次都来执行这个任务,下面我们给该任务添加快捷方式来实现快速打开任务程序。

二、为任务创建快捷方式

我们在桌面上创建一个快捷方式


接下来填写任务执行信息:


其中“AdminCmd”就是我们任务名称。(如果不清楚schtasks这个命令格式可以去cmd中/?查询一下)然后下一步,给快捷方式启一个名称,即可。标题应该是taskeng.exe


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Windows 中,要以管理员权限运行一个进程并绕过 UAC 提示,可以使用以下方法: 1. 使用 ShellExecuteEx 函数启动进程。该函数可以在指定的进程上下文中启动应用程序。 2. 在启动进程之前,需要创建一个管理员特权的进程令牌。可以使用 OpenProcessToken 和 DuplicateTokenEx 函数来创建一个管理员特权的令牌。 3. 使用 CreateProcessAsUser 函数以管理员权限运行指定的进程。这个函数会将进程启动在指定的用户上下文中。 下面是一个简单的 C++ 代码示例: ``` #include <windows.h> #include <sddl.h> #include <userenv.h> #include <shlobj.h> #include <iostream> void RunElevated(const wchar_t* cmdLine) { SHELLEXECUTEINFO sei = { sizeof(sei) }; sei.lpVerb = L"runas"; sei.lpFile = cmdLine; sei.hwnd = NULL; sei.nShow = SW_NORMAL; if (!ShellExecuteEx(&sei)) { DWORD error = GetLastError(); if (error == ERROR_CANCELLED) { // The user refused to allow privileges elevation. std::cerr << "User refused to allow privileges elevation.\n"; } else { std::cerr << "Failed to elevate privileges. Error code: " << error << "\n"; } } } int main() { // Get the current process token. HANDLE tokenHandle; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &tokenHandle)) { std::cerr << "Failed to open process token. Error code: " << GetLastError() << "\n"; return 1; } // Duplicate the token with admin privileges. HANDLE elevatedTokenHandle; if (!DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, NULL, SecurityIdentification, TokenPrimary, &elevatedTokenHandle)) { std::cerr << "Failed to duplicate process token. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); return 1; } // Set the elevation level of the new token to full. TOKEN_ELEVATION_TYPE elevationType; DWORD elevationSize = sizeof(TOKEN_ELEVATION_TYPE); if (!GetTokenInformation(elevatedTokenHandle, TokenElevationType, &elevationType, sizeof(elevationType), &elevationSize)) { std::cerr << "Failed to get token information. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); return 1; } if (elevationType != TokenElevationTypeFull) { TOKEN_ELEVATION elevation = { 0 }; elevation.TokenIsElevated = 1; if (!SetTokenInformation(elevatedTokenHandle, TokenElevation, &elevation, sizeof(elevation))) { std::cerr << "Failed to set token information. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); return 1; } } // Get the user name and domain name for the current user. DWORD size = 0; GetUserNameEx(NameSamCompatible, NULL, &size); std::wstring userName(size, L'\0'); GetUserNameEx(NameSamCompatible, &userName[0], &size); size = 0; GetComputerNameEx(ComputerNameDnsDomain, NULL, &size); std::wstring domainName(size, L'\0'); GetComputerNameEx(ComputerNameDnsDomain, &domainName[0], &size); // Create the user profile for the new user token. PROFILEINFO profileInfo = { sizeof(profileInfo) }; profileInfo.dwFlags = PI_NOUI; profileInfo.lpUserName = &userName[0]; profileInfo.lpProfilePath = L""; profileInfo.lpDefaultPath = L""; profileInfo.lpServerName = &domainName[0]; profileInfo.lpPolicyPath = L""; profileInfo.hProfile = NULL; DWORD sessionId; HANDLE userTokenHandle; if (!CreateProfile(&profileInfo, &userTokenHandle)) { std::cerr << "Failed to create user profile. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); return 1; } if (!ProcessIdToSessionId(GetCurrentProcessId(), &sessionId)) { std::cerr << "Failed to get session ID. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); CloseHandle(userTokenHandle); return 1; } if (!ImpersonateLoggedOnUser(userTokenHandle)) { std::cerr << "Failed to impersonate user. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); CloseHandle(userTokenHandle); return 1; } // Get the path to the executable. wchar_t exePath[MAX_PATH]; if (GetModuleFileName(NULL, exePath, MAX_PATH) == 0) { std::cerr << "Failed to get executable path. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); CloseHandle(userTokenHandle); return 1; } RunElevated(exePath); // Restore the original token and close the elevated token. if (!RevertToSelf()) { std::cerr << "Failed to revert to self. Error code: " << GetLastError() << "\n"; CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); CloseHandle(userTokenHandle); return 1; } CloseHandle(tokenHandle); CloseHandle(elevatedTokenHandle); CloseHandle(userTokenHandle); return 0; } ``` 这个代码示例使用了 ShellExecuteEx 函数来以管理员权限运行指定的进程。如果进程启动失败,将会输出错误信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值