如何关闭所有窗口

Luk*_*101 5 powershell batch-file powershell-2.0

我想关闭所有打开的窗户.这不会最小化窗口,但脚本将关闭所有窗口,即使它被最小化.有没有办法在批处理程序或PowerShell中执行此操作?

CB.*_*CB. 12

在powershell中使用它:

Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process
Run Code Online (Sandbox Code Playgroud)

- 注意:这个关闭powershell console或者ise也不能结束他的工作!

(get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" } )| stop-process
Run Code Online (Sandbox Code Playgroud)

这种方式只有powershell窗口仍然存在,但脚本中的最后一个命令可以

stop-process powershell
Run Code Online (Sandbox Code Playgroud)

注意:这不会影响托盘图标最小化过程.

编辑:

关闭xp上的'控制面板'试试这个:

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

关闭所有explorer.exe窗口:

(New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()}
Run Code Online (Sandbox Code Playgroud)