Answers:
这是我目前知道将此功能添加到Windows资源管理器中的上下文菜单的唯一方法:
[在提升的Powershell提示中运行此脚本]
$menu = 'Open Windows PowerShell Here as Administrator'
$command = "$PSHOME\powershell.exe -NoExit -NoProfile -Command ""Set-Location '%V'"""
'directory', 'directory\background', 'drive' | ForEach-Object {
New-Item -Path "Registry::HKEY_CLASSES_ROOT\$_\shell" -Name runas\command -Force |
Set-ItemProperty -Name '(default)' -Value $command -PassThru |
Set-ItemProperty -Path {$_.PSParentPath} -Name '(default)' -Value $menu -PassThru |
Set-ItemProperty -Name HasLUAShield -Value ''
}
该脚本来自以下链接:
我99%确信这是我在最新的Windows补丁“删除”我的注册表设置之前所做的方式(它还删除了一些其他自定义设置,例如numlock引导状态,但这并不那么令人讨厌)。
如果有人知道更好的方法;即那不会波动,那么请让我知道,我会接受这个答案。
-NoProfile
开关,以在启动提示时自动加载您的配置文件。
我一直在这样做。这是我做的一个小菜单的一部分。根据自己的喜好进行编辑:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\OAPS.Tools]
"ImpliedSelectionModel"=dword:00000001
"Icon"="imageres.dll,-5373"
"ExplorerCommandHandler"="{BF0AC53F-D51C-419F-92E3-2298E125F004}"
@="Admin Pshell Here"
这是我用来将CMD和POWERSHELL都添加到Windows 10中任何文件夹的Background上下文菜单的reg文件的副本:
Windows Registry Editor Version 5.00
;Add_Open_CMD_and_Powershell_to_Context_Menu.reg
;Right-Click Background only
;CMD Prompt
[HKEY_CLASSES_ROOT\Directory\Background\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuCmd"
[HKEY_CLASSES_ROOT\Directory\Background\shell\01MenuCmd] "MUIVerb"="Command Prompts" "Icon"="cmd.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuCmd"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\open] "MUIVerb"="Command Prompt" "Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\open\command] @="cmd.exe /s /k pushd \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\runas] "MUIVerb"="Command Prompt Elevated" "Icon"="cmd.exe" "HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuCmd\shell\runas\command] @="cmd.exe /s /k pushd \"%V\""
; PowerShell
[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuPowerShell"
[HKEY_CLASSES_ROOT\Directory\Background\shell\02MenuPowerShell] "MUIVerb"="PowerShell Prompts" "Icon"="powershell.exe" "ExtendedSubCommandsKey"="Directory\Background\ContextMenus\MenuPowerShell"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open] "MUIVerb"="PowerShell" "Icon"="powershell.exe"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\open\command] @="powershell.exe -noexit -command Set-Location '%V'"
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas] "MUIVerb"="PowerShell Elevated" "Icon"="powershell.exe" "HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\ContextMenus\MenuPowerShell\shell\runas\command] @="powershell.exe -noexit -command Set-Location '%V'"