首页 > 解决方案 > 删除 over powershell windows 10 Apps

问题描述

我构建了一个脚本来删除每个 Python 的 Windows 10 应用程序。我将要删除的应用程序保存在字符串数组中,并将完整的命令保存在变量中。

然后我运行命令,出现错误:Remove-AppxPackage 命令拼写错误或找不到。

我编写了以下代码:

    win10Apps = ["3d", "camera"]
       for app in win10Apps:
       psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
       pyautogui.press("Enter")
       os.system("powershell.exe " + psCommand)
       pyautogui.press("Enter")

标签: pythonpowershellwindows-10

解决方案


正如 JosefZ 在评论中提到的那样,您必须在调用其他可执行文件时格式化您的参数。

固定代码如下所示:

win10Apps = ["3d", "camera"]
for app in win10Apps:
    psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
    pyautogui.press("Enter")
    os.system('powershell.exe -c "{}"'.format( psCommand))
    pyautogui.press("Enter")

同样对于特殊字符,您需要转义。此外,这里是Get-AppxPackageRemove-AppxPackage的文档。


推荐阅读