[当在VSCode中使用PowerShell v5 x64和x86的VSCode中时,它返回以下内容:
Get-ExecutionPolicy -list
[在VSCode中使用相同命令并使用PowerShell v7控制台时,它返回:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Bypass
CurrentUser Undefined
LocalMachine Undefined
有2个设置ExecutionPolicy的注册表项(最初是:ByPass)
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Undefined
LocalMachine RemoteSigned
这2个条目最初被设置为将执行策略设置为ByPass,而我将这2个条目手动设置为RemoteSigned。 (为什么这两个条目在注册表中,为什么将它们设置为绕过?!)。
在注册表中没有为PowerShell设置的其他策略,而是这两个条目。将这些设置为RemoteSigned似乎已经完成了v7的技巧,但没有完成v5的技巧。
[在v5 PowerShell控制台中检查ExecutionPolicy时,它们都是未定义的。
当检查vscode-powershell.log时,它说它以参数启动PowerShell: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'"
我可以看到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后,可能会发生这种情况:PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module ...
我未使用任何配置文件。
我知道这有点混乱,对此感到抱歉,我的主要问题是,在启动语言服务器时,VSCode在哪里设置ExecutionPolicy,我可以更改它。在进行调查时,我发现有2个注册表项将ExecutionPolicy设置为bypass,为什么那是标准的,看起来像一个安全问题。 (可能是由于安装Chocolatey引起的,不确定)
[在用于PowerShell v5 x64和x86的VSCode中使用Get-ExecutionPolicy -list时,它返回以下内容:范围ExecutionPolicy ----- ---------------未定义的MachinePolicy ...] >
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'))
的PowerShell extension遵循配置为使用的任何PowerShell版本/版本的执行策略设置(要管理这些设置,请使用相应版本/版本的Visual Code。
如果要覆盖