[英]Check if Windows File Explorer is already opened in python
I have simple script that launches Windows File Explorer我有启动 Windows 文件资源管理器的简单脚本
import subprocess
subprocess.call(["start", "explorer.exe"],shell=True)
I'd like to check if Windows File Explorer is already opened so that I don't open another instance.我想检查 Windows 文件资源管理器是否已经打开,这样我就不会打开另一个实例。 How can I do it?我该怎么做? Solutions without external libraries are preferred.没有外部库的解决方案是首选。
Found the solution找到解决方案
import win32gui
explorerWindows = []
def handler( hwnd, list ):
# only explorer windows have class 'CabinetWClass'
if 'CabinetWClass' in win32gui.GetClassName(hwnd):
list.append(hwnd)
win32gui.EnumWindows(handler, explorerWindows)
explorerOpened = len(explorerWindows) > 0
EDIT: easier method编辑:更简单的方法
import win32gui
explorerOpened = win32gui.FindWindow('CabinetWClass', None) != 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.