r/visualbasic • u/DMM710 • May 09 '20
Is it possible to create a macro that closes all programs that are open in the task bar?
1
u/infreq May 09 '20
May I ask why?
1
u/DMM710 May 10 '20
Because I use a lot of different programs and open a lot of instances of each program. Also I have a bad habit of leaving things open when I'm done with them. At the end of the day I end up with like 5 instances of firefox, notepad, postman, pycharm, file explorer and a bunch of other crap open when I'm done using my computer lmao.
1
u/infreq May 10 '20
A few ALT-F4? A few CTRL-W to close browser tabs?
Or use a utility for it: https://www.online-tech-tips.com/computer-tips/how-to-kill-or-close-all-running-programs-in-windows-quickly/
1
u/DMM710 May 10 '20
the CTRL+W is pretty nice. Didn't know about that one. ALT-F4 doesn't really help because each window asks me if i want to save
1
u/MildewManOne Jul 08 '20
Couldn't you use the enumwindows function, pass the hWnds to IsWindowVisible and then end the process if it returns true?
8
u/paintballboi07 VB.Net Advanced May 09 '20 edited May 09 '20
You can use Process.GetProcesses() and check for those with a non null/empty MainWindowTitle. Here is a Stack Overflow answer on the same type of question..
Edit: Sorry submitted comment without finishing, once you find the processes that have a MainWindowTitle, you can just call Process.Close() or Process.Kill(). The differences between the two are here: https://stackoverflow.com/questions/13952635/what-are-the-differences-between-kill-process-and-close-process