Running a command as Administrator using PowerShell?

后端 未结 26 2848
粉色の甜心
粉色の甜心 2020-11-22 09:41

You know how if you\'re the administrative user of a system and you can just right click say, a batch script and run it as Administrator without entering the administrator p

26条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 10:07

    You can easily add some registry entries to get a "Run as administrator" context menu for .ps1 files:

    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"'
    

    (updated to a simpler script from @Shay)

    Basically at HKCR:\Microsoft.PowershellScript.1\Shell\runas\command set the default value to invoke the script using Powershell.

提交回复
热议问题