试图执行程序然后最小化所有窗口的问题

发布于 2025-01-31 02:47:50 字数 760 浏览 2 评论 0原文

我正在尝试执行Windows批处理文件,然后使用Python最大程度地减少打开的每个窗口(以使我的Windows 11屏幕清洁),但我无法实现目标。 我的代码能够执行批处理或最小化所有窗口,但不能将两个功能一起使用,我找不到解决方案的方法。 基本上想执行我的批处理,然后最小化所有窗口,通过这种方式,我可以在Windows 11引导下执行Python脚本,以便打开我的批处理,然后最小化所有内容,以便终端窗口不保持打开状态并使我的屏幕使我的屏幕保持清洁,因为什么都没发生:)

这里的问题是批次正在成功运行,但窗户没有最小化,如果我删除 os.startfile 功能,并且仅保留 pyautogui.hotkey.hotkey. 功能,现在窗口已被最小化,但批处理不运行。 我不能保持两个功能一起工作。 谢谢你的时间

import pyautogui
import time
import os

os.startfile('"C:/Users/villa/Desktop/ETH.lnk"') #Excecutes the batch.
time.sleep(5) #Waits 5 secs to make sure the batch is already running before minimizing everything.
pyautogui.hotkey('win','m') #This is the Windows hotkey that minimizes all windows.

I'm trying to execute a Windows Batch file and then minimize every single window that is open (to make my Windows 11 screen clean) using Python but Im not fulfilling the objective.
My code is able to execute the Batch OR minimize all the windows but not both functions together and I can't find a way to fix it.
Basically want to execute my batch and then minimize all the windows, in this way I can make the Python script execute at Windows 11 boot so it will open my batch and then minimize everything so the terminal window doesn't keep open and makes my screen clean as nothing happened :)

The problem here is that the batch is running successfully but windows are not getting minimized, this changes if I remove the os.startfile function and only keep the pyautogui.hotkey function, now the the windows are getting minimized but clarely the batch is not running.
I can't keep both functions working together.
Thanks for your time

import pyautogui
import time
import os

os.startfile('"C:/Users/villa/Desktop/ETH.lnk"') #Excecutes the batch.
time.sleep(5) #Waits 5 secs to make sure the batch is already running before minimizing everything.
pyautogui.hotkey('win','m') #This is the Windows hotkey that minimizes all windows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笛声青案梦长安 2025-02-07 02:47:50
import pyautogui
import time
import subprocess
subprocess.Popen([r'cmd.exe', '/c start /b C:\Users\villa\Desktop\ETH.lnk'])
pyautogui.hotkey('win','m')
import pyautogui
import time
import subprocess
subprocess.Popen([r'cmd.exe', '/c start /b C:\Users\villa\Desktop\ETH.lnk'])
pyautogui.hotkey('win','m')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文