【发布时间】:2021-06-29 09:56:04
【问题描述】:
我想在这种情况下使用脚本:
- 无需管理员权限即可获得远程访问权限
- 以
.\Administrator的身份远程启动 Quick Assist 而不是进行 UAC 对话。
第 1 步通常使用 Quick Assist,有时使用 Teams 屏幕共享。
我知道我可以在文件资源管理器中找到 quickassist.exe,然后使用 Shift 和上下文菜单来以其他用户身份运行,但我想脚本化方法。
实验A
这可行,但有一个是/否 UAC 对话:
$isElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ( -not $isElevated ) {
Start-Process powershell.exe -Credential Administrator -NoNewWindow -ArgumentList {
Start-Process quickassist.exe -Verb RunAs ;
} ;
}
实验 B
我犯了很多错误,不知道如何改正。 (我正在尝试逐步学习 PowerShell,但我在学习时很容易感到困惑;有点阅读障碍。)
$isElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ( -not $isElevated ) {
Start-Process powershell.exe -Credential Administrator {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "PromptOnSecureDesktop" -Value 0 -Force;
};
Write-Host "UAC (user account control) is weakened for a Quick Assist session …" -ForegroundColor Red;
Start-Process powershell.exe -Credential Administrator -NoNewWindow -ArgumentList {Start-Process quickassist.exe -Verb RunAs -Wait};
Write-Host "… Quick Assist session complete …" -ForegroundColor Red;
Start-Process powershell.exe -Credential Administrator {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "PromptOnSecureDesktop" -Value 1 -Force;
};
Write-Host "… UAC is strengthened." -ForegroundColor Red;
}
- 未发生对注册表的两项预期更改
- 第三个凭据对话框出现得太快了 - 我希望它在快速协助会话结束之前不出现。
此外,从概念上讲,当 UAC 暂时被削弱时,可能不需要以管理员身份运行 Quick Assist。
参考文献
https://stackoverflow.com/a/2258134/38108 (2010-02-13) 我看到 -Credential 与 Invoke-Command 一起使用,但是当我尝试做类似的事情时,为了更改注册表,我搞砸了。
https://stackoverflow.com/a/47516161/38108 (2017-11-27) 自升式 PowerShell 脚本。
https://superuser.com/a/1524960/84988 (2020-02-12) 和 https://serverfault.com/a/1003238/91969 (2020-02-15) 很有趣——两个答案中的脚本相同——但是我需要像 -Credential Administrator 这样的东西来代替 -ComputerName。
https://stackoverflow.com/a/60292423/38108 (2020-03-07) 通过https://stackoverflow.com/a/60263039/38108
PowerShell commands - PowerShell - SS64.com
https://github.com/okieselbach/Intune/blob/master/DisablePromptOnSecureDesktop.ps1 (2020-11-13) 通过Quick Assist the built-in Remote Control in Windows 10 – Modern IT – Cloud – Workplace
【问题讨论】:
-
当你使用这样的逻辑时它是否有效...pastebin.com/YTHKn72Y。在示例 b 中的另一个启动进程中存在启动进程,因此
-wait参数可能需要与外部启动进程而不是内部启动进程一起使用。我通常不会在任何本地计算机上运行它,它总是在远程计算机上运行,我将帮助非管理员用户在同一网络上执行任务并连接到同一域。您不能针对您正在连接的远程计算机远程调用命令吗? -
还有用于禁用安全桌面的 reg 设置,以允许您查看 UAC 并自己输入凭据,而不是让非管理员用户输入它们,您会看到 UAC 屏幕远程需求并与之交互无论它是提升还是以管理员身份运行,都运行。从
isElevated逻辑中取出该逻辑并始终在没有任何条件的情况下运行它,然后在没有条件的情况下重新启用其他 reg 设置。看看这些东西是否有帮助。 -
UAC 旨在防止您这样做。 (如果 UAC 这么容易绕过,那么这正是所有恶意软件都会做的事情。)
-
Bill_Stewart 你误会了。我没有试图绕过身份验证对话。
-
好的,如果您更喜欢这个术语,UAC 旨在仅在显示请求此权限的对话框后才允许提升。 (如果这是可能的,那么所有恶意软件都可以以管理员身份感染您的计算机而不受惩罚。)
标签: windows powershell uac remote-desktop user-account-control