自动设置注册表值(executionpolicy),以便我可以通过Python运行powershell脚本

2024-06-30 15:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从Python运行powershell脚本。 我这里有一个代码:

import subprocess

subprocess.Popen(["powershell.exe","C:\\Users\\Someone\\Documents\\Scripts\\Script.ps1"])

但当我这么做的时候,我会

cannot be loaded because running scripts 
is disabled on this system. For more information, see about_Execution_Policies at ...

我在网上做了一些调查,发现我需要找到

ExecutionPolicy

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

我需要将它修改为

Unrestricted

所以现在,我的目标是让我的Python代码自动检查这一点,并将其设置为无限制,或者创建一个具有无限制值的新ExecutionPolicy(我的计算机就是这样)

我真的不知道在哪里或如何尝试这一点


Tags: 代码import脚本scriptsscriptexeusersdocuments