[英]Powershell Execution Policy is restricted, but only when run through python
我有一个 Windows Server 2008 盒子。 我以管理员身份在 Powershell Set-ExecutionPolicy Unrestricted 中运行。 当我运行powershell Get-ExecutionPolicy
,它返回 Unrestricted。
我创建了一个 .bat 文件,它展示了我所看到的问题。 .bat 文件 test.bat 只有一行, powershell Get-ExecutionPolicy
。 当我打开命令提示符并运行 test.bat 时,屏幕上会打印“Unrestricted”。
但是,如果我运行以下 python 脚本,
import subprocess
subprocess.Popen("test.bat")
“受限”被打印到屏幕上。 从 Python 的 subprocess.Popen 运行时,此设置有何不同? 我在 Windows 7 机器上没有看到这个问题,我在那里执行了相同的工作流程。
我找到了答案。 Unrestricted ExecutionPolicy 适用于 64 位版本的 powershell。 Python 最终调用了我没有设置的 32 位版本。 Windows Server 2008 包括两个版本的 powershell,但 Windows 7 没有。
请参阅: PowerShell 说“在此系统上禁止执行脚本”。 更多细节
以管理员身份在powershell中运行以下代码
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.