你好,我有这个 reg 脚本来添加密钥以以管理员身份在目录中运行 powershell...但我需要将这个选项添加到扩展名为“.ps1”的文件中...我需要添加什么???
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd.exe -ArgumentList '/s,/c,pushd %V && powershell' -Verb RunAs\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd.exe -ArgumentList '/s,/c,pushd %V && powershell' -Verb RunAs\""
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd.exe -ArgumentList '/s,/c,pushd %V && powershell' -Verb RunAs\""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd.exe -ArgumentList '/s,/c,pushd %V && powershell' -Verb RunAs\""
更新
我尝试使用这个但不能正常工作:
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\OpenElevatedPS]
@="Ejecutar con PowerShell como Administrador"
"Icon"="powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process cmd.exe -ArgumentList '/s,/c,pushd %V && powershell' -Verb RunAs\""
答案1
为了使其针对文件扩展名运行,您通常需要为传递的文件名添加一个变量%1
,,
不过我认为还有更简单的解决方案。请参阅这里
摘录:保存为 powershellrunas.reg 并双击它。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\runas\command]
@="powershell.exe \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""