Powershell执行策略受到限制,但仅限于在python中运行时

时间:2014-06-05 18:21:17

标签: python windows powershell executionpolicy

我有一个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机器上看到这个问题,我在那里执行了相同的工作流程。

2 个答案:

答案 0 :(得分:1)

我找到了答案。 Unrestricted ExecutionPolicy用于64位版本的powershell。 Python最终调用32位版本,我没有设置。 Windows Server 2008包括两个版本的PowerShell,但Windows 7没有。

请参阅: PowerShell says "execution of scripts is disabled on this system." 了解更多详情

答案 1 :(得分:0)

以管理员身份在powershell中运行以下代码

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned