gpt4 book ai didi

powershell - 取消提升 PowerShell session

转载 作者:行者123 更新时间:2023-12-04 15:51:19 25 4
gpt4 key购买 nike

我有一个以管理员身份运行的 PowerShell 脚本,它调用的另一个脚本不需要以管理员身份运行。我用过 Start-Process -FilePath "powershell.exe" -Verb runas之前提升,但如何从已经以管理员身份运行的 session 中“取消提升”?

我想避免使用第三方工具,例如 psexec那个this post用途。理想情况下寻找内置 PS 功能或 PSSnapin。

需要此“未提升” session 的特定过程是查看由管理员安装的驱动器。根据这个article UAC 可能是罪魁祸首。提出的解决方案是运行以​​下内容:
New-ItemProperty -Path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLinkedConnections -Value 1 -PropertyType DWord
但是,驱动器在 Get-PSDrive 时仍然不显示在提升的 session 中运行。

最佳答案

您可以尝试使用内置的 runas.exe 进行“取消提升”,如本答案 Batch file: Drop elevated privileges (run a command as original user)

runas /trustlevel:0x20000 "YourCommandHere"

关于powershell - 取消提升 PowerShell session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53727582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com