[英]Start a program with a bat file taking administrator privileges without asking with UAC
[英]Windows 10: after gaining remote access, remotely start Quick Assist as .\Administrator without UAC, or temporarily disable UAC
我想在這種情況下使用一個腳本:
.\Administrator
身份遠程啟動 Quick Assist並且沒有UAC 對話。第 1 步通常使用 Quick Assist 進行,有時使用 Teams 屏幕共享進行。
我知道我可以在文件資源管理器中找到quickassist.exe
,然后使用Shift和上下文菜單來Run as a different user ,但是我想要一種腳本方法。
這可行,但有一個是/否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 ;
} ;
}
我犯了很多錯誤,不知道如何改正。 (我正在嘗試逐步學習 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-150) 中的相同腳本都很有趣– 但是我需要-Credential Administrator
之類的東西來代替-ComputerName
。
https://stackoverflow.com/a/60292423/38108 (2020-03-07) 通過https://stackoverflow.com/a/60263039/38108
PowerShell 命令 - PowerShell - SS64.com
https://github.com/okieselbach/Intune/blob/master/DisablePromptOnSecureDesktop.ps1 (2020-11-13) 通過快速協助 Windows 10 中的內置遠程控制 - 雲 - 工作場所現代 IT - 雲
簡短的回答是不要。 獲取真正的遠程管理工具或讓某人點擊 UAC 是提示。
這比 powershell 更像是 windows 的事情,因為 windows 明確拒絕在本地提升進程而無需通過 UAC(並且有充分的理由這樣做:)。
# Use Enter-PSSession to start a "remote" session
# This may still support elevation if you specify CredSSP and configure credential delegation):
New-PSSession MyPCName -Auth CredSSP -cred (get-credential)
# Create a scheduled task with RunAs/elevated permissions:
Register-ScheduledTask -Action $action -User .\Administrator -TaskName "Admin-Stuff" -RunLevel Highest
現在在本地運行時會給出胖訪問被拒絕的消息。 您也無法在HKLM:
沒有提升,因此暫時禁用 uac 不是一個選項。
您也許可以利用這個允許管理員用戶繞過 uac 的漏洞,但我認為您仍然必須以其他用戶身份運行您的 shell 才能使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.