簡體   English   中英

Powershell 執行策略受到限制,但僅當通過 python 運行時

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM