你知道,如果你是一个系统的管理用户,你可以直接右键点击一个批处理脚本,以管理员身份运行,而不需要输入管理员密码。
我想知道如何用PowerShell脚本做到这一点。我不想输入密码,我只想模仿右键单击以管理员身份运行的方法。
到目前为止,我读到的所有内容都要求你提供管理员密码。
你可以很容易地添加一些注册表项,为".ps1 "文件获得一个"以管理员身份运行"上下文菜单。
New-Item -Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowershellScript.1\Shell\runas\command" `
-Force -Name '' -Value '"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -noexit "%1"'
(更新为@Shay提供的一个更简单的脚本)
基本上在HKCR:\Microsoft.PowershellScript.1\Shell\runas\command
设置默认值,用Powershell调用脚本。