How to close all windows

I would like to close all open windows. This does not minimize windows, but the script will close all windows, even if they are minimized. Is there a way to do this in a batch program or powershell?

+4
source share
1 answer

use this in powershell:

Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process 

-note: this closes the powershell console or ise too and cannot finish the job!

 (get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" } )| stop-process 

this way, only PowerShell windows are still alive, but the last command in your script might be

 stop-process powershell 

Note: this does not affect the minimization of the tray icon process.

EDIT:

to close the "control panel" on xp, try the following:

 (New-Object -comObject Shell.Application).Windows() | where-object {$_.LocationName -eq "Control Panel"} | foreach-object {$_.quit()} 

close all windows explorer.exe:

 (New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()} 
+11
source

Source: https://habr.com/ru/post/1401668/


All Articles