如何使用 python 关闭所有 windows7 文件夹

How to close all windows7 folders using python

我正在使用 python 2.7,我同时使用许多打开的 windows7 文件夹和其他程序。我已经尝试使用此代码(工作正常完美):

import os

os.system('taskkill /im chrome.exe')
os.system('taskkill /im powerpnt.exe')
os.system('taskkill /im outlook.exe')
os.system('taskkill /im winword.exe')
os.system('taskkill /im excel.exe')

但我也不知道如何同时关闭所有文件夹和文件 (windows 7)。 我尝试了以下

how to close remote desktop window using python

How to Close a program using python?

How to close all windows

但不明白 python 的方法。 另外,我试图在任务管理器中搜索名称进程,但我不知道它的名称。

有没有可能在不损坏电脑操作系统的情况下做到?

您可以使用 nircmd(您需要安装 nircmd - http://www.nirsoft.net/utils/nircmd.html

和子流程模块:

import subprocess
subprocess.call('nircmd.exe win close class "CabinetWClass"' , shell=True)