【发布时间】:2020-04-13 06:55:06
【问题描述】:
在 VSCode 中为 PowerShell v5 x64 和 x86 使用 Get-ExecutionPolicy -list 时,它会返回以下内容:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Bypass
CurrentUser Undefined
LocalMachine Undefined
在 VSCode 中使用相同的命令并使用 PowerShell v7 控制台时,它会返回:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Undefined
LocalMachine RemoteSigned
有 2 个注册表项设置了 ExecutionPolicy(原文:ByPass)
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0\Command REG_SZ "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process RemoteSigned }; & '%1'"
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\0\Command REG_SZ "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process RemoteSigned }; & '%1'"
这 2 个条目最初设置为将执行策略设置为 ByPass,我已手动将这 2 个条目设置为 RemoteSigned。 (为什么这两个条目在注册表中,为什么它们被设置为绕过?!)。
在注册表中没有为 PowerShell 设置更多策略,然后是这 2 个条目。 将这些设置为 RemoteSigned 似乎已经为 v7 解决了问题,但对于 v5 却没有。
在 v5 PowerShell 控制台中检查 ExecutionPolicy 时,它们都是未定义的。
检查 vscode-powershell.log 时,它说它使用参数启动 PowerShell:PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module ...
我可以看到 vscode powershell 扩展在以下文件中设置了其中一些参数:
C:\Users\UserName.vscode\extensions\ms-vscode.powershell-2020.3.0\out\src\process.js
但我不确定这是否是进行这些更改的正确文件。
我希望能够在启动语言服务器时检查/设置 VSCode 的 ExecutionPolicy 为 RemoteSigned,我应该在哪里执行此操作?
另外,当 ExecutionPolicy 不等于 AllSigned 时,为什么注册表中有 2 个条目将 ExecutionPolicy 设置为 ByPass。这可能是在使用他们的单行安装程序安装 Chocolatey 后发生的:Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
我没有使用任何个人资料。
我知道它有点乱,很抱歉,我的主要问题是 VSCode 在启动语言服务器时设置 ExecutionPolicy 的位置,我可以更改它吗? 在进行一些调查时,我发现有 2 个注册表项将 ExecutionPolicy 设置为 bypass ,这是为什么,是标准,看起来像一个安全问题。 (这可能是由于安装巧克力造成的,不确定)
【问题讨论】:
-
认为设置 ExecutionPolicy 的 2 个注册表项没有指向任何可以正常启动的 shell。在启动它们中的任何一个时,它们不会影响控制台外壳中的 ExecutionPolicy。不是 v5 控制台和 ISE ,也不是 v7 ,也不是 x86 或 x64 ......他们指向什么 shell,为什么这些条目在那里?
-
为进程设置执行策略并没有帮助,因为重新启动 VSCode 会将其设置回绕过。
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Undefined -Force -Verbose
标签: powershell visual-studio-code registry vscode-settings