Closing All Explorer Windows

Sometimes, explorer windows clutter up the desktop. You can use a COM library called Shell.Application to automatically close all open explorer windows and clean up your windows world programmatically. Use the following line:

(New-Object -comObject Shell.Application).Windows() | ? { $_.FullName -ne $null} | ? {
$_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() }

Essentially, this line instantiates the COM object, uses its Windows() method to retrieve all ShellWindow windows (including IE and Outlook), then filters the windows so that only true explorer windows are left, and finally quits all explorer windows.

Hungry for more? Check out this blog entry!


Posted Oct 28 2008, 08:00 AM by Tobias Weltner

Comments

pudding wrote re: Closing All Explorer Windows
on 12-20-2008 10:24 PM

The script works when there is at least one Explorer running background.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.