How to close all windows

大城市里の小女人 提交于 2019-11-29 22:14:32

问题


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


回答1:


use this in powershell:

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

-note: this close powershell console or ise too and can't end his job!

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

this way only powershell windows is still alive but the last command in your script can be

stop-process powershell

note: this no affect tray icon minimized process.

EDIT:

to close 'control panel' on xp try this:

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

to close all explorer.exe windows:

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


来源:https://stackoverflow.com/questions/9725629/how-to-close-all-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!