1

I have a Windows Server 2008 box. I have run, as administrator, in powershell Set-ExecutionPolicy Unrestricted. When I run powershell Get-ExecutionPolicy, it returns Unrestricted.

I have created a .bat file which exhibits the issue I am seeing. The .bat file, test.bat, is only one line, powershell Get-ExecutionPolicy. When I open command prompt and run test.bat, "Unrestricted" is printed to the screen.

If I run the following python script however,

import subprocess
subprocess.Popen("test.bat")

"Restricted" is printed to the screen. How is this setting different when being run from Python's subprocess.Popen? I am not seeing the issue on a Windows 7 machine I have, where I have performed an identical workflow.

4

2 回答 2

1

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

请参阅: PowerShell 说“在此系统上禁用了脚本的执行”。 更多细节

于 2014-06-06T19:34:20.507 回答
1

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

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
于 2020-03-21T07:07:54.580 回答