安装 VS Code 后从文件资源管理器执行 Powershell

Execute Powershell from File Explorer after installing VS Code

VS Code 试图将自己定位为使用 Powershell 的新方式,它在安装时所做的其中一项更改是替换 .[=18= 上的文件资源管理器上下文菜单选项 "Run with PowerShell" ] 文件,而不是使用新的 "Open with Code" 选项。

有没有办法删除 "Open with Code" 选项并将其替换为旧的 "Run with PowerShell" 选项?我认为这会以某种方式涉及注册表,但我对注册表的了解还不够多,无法安全地进行操作。

VS Code 并没有真正将自己定位为使用 PowerShell 的新方式,它将是唯一 "built-in" 与 Windows 一起使用它的方式,因为 PowerShell ISE 正在贬值。

无论哪种方式,VS Code 都没有导致该选项消失。我的机器上有 VS Code 和 PS 扩展,并且仍然可以访问这两个选项:

当您安装 VS Code 时,系统会提示您添加右键单击菜单选项,因此如果您选择加入这些选项,那么它并不是删除您的 "Run with PowerShell" 选项的原因。

如果要删除这些右键单击选项,则必须卸载 VS Code 并重新安装,确保未选中这些选项。

要将菜单选项恢复为 Run with PowerShell,请确认您没有更改 PowerShell 文件的默认程序(例如 ps1)。如果您将其设置为 VS Code,它将导致该选项从您的右键单击菜单中删除。您可以通过将 Windows 中的默认程序改回记事本来恢复它。

试试这个:

将以下内容保存到文件"EnablePowerShellRightClickRun.reg",然后右键-合并。

然后将 .ps1 文件关联到哪个应用程序都没有关系 - 您仍然有 "Run with Powershell" 作为右键单击选项。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS]
@="Run with Powershell"

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS\command]
@="\"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe\" -File \"%1\""