'Issue trying to execute a program and then minimize 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.
Solution 1:[1]
import pyautogui
import time
import subprocess
subprocess.Popen([r'cmd.exe', '/c start /b C:\Users\villa\Desktop\ETH.lnk'])
pyautogui.hotkey('win','m')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user15611379 |
