python - 从 python 脚本解锁 Windows 中的文件

标签 python powershell

我可以在 windows(7) 中取消阻止 Windows(从互联网下载)中通过 python 脚本自动阻止的文件吗?遇到此类文件时会引发 WindowsError。我想捕获这个异常,并运行一个 powershell 脚本,如下所示:

Parameter Set: ByPath
Unblock-File [-Path] <String[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: ByLiteralPath
Unblock-File -LiteralPath <String[]> [-Confirm] [-WhatIf] [ <CommonParameters>]

我不知道 powershell 脚本。但如果我有的话,我可以从 python 中调用它。大家能帮忙吗?

最佳答案

是的,您所要做的就是从 Python 调用以下命令行:

powershell.exe -Command Unblock-File -Path "c:\path\to\blocked file.ps1"

关于python - 从 python 脚本解锁 Windows 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20886450/

相关文章:

python - sed 在 python 中带有空格

用于设置 pagefile.sys 大小的 PowerShell 脚本

powershell - Powershell 中的显式返回

csv - CSV 中的查找值和第二列的返回值

python - 无法使用 Postgres、Docker Compose 和 Psycopg2 将主机名 "db"转换为地址

python - 在Python中使用从父类继承的方法时返回子类的新实例

python - Non_field_errors django webapi 中没有提供数据

python - 从字典列表创建 Dataframe,不使用 pd.concat()

powershell - 使用 powershell : Unwanted results 从 Outlook 获取今天的约会

dom - 使用 DOM 从网站获取 HTML