Close All Opened Windows by One Cmd Command

I would like to close all opened windows (from programs, windows explorer, etc...) by using CMD. The easiest way I found is not using CMD but running these two powershell commands:

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

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

Which works pretty well, but I don't know how to execute them right from CMD. I tried the commands below using powershell -noexit to execute powershell commands and ^ to ignore some cmd functions, but it does not work:

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

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

And I do not want to use taskkill command or create a .ps1 file and execute it by using start .ps1 either.

4

1 Answer

Solved by PetSerAl.

powershell -command "(New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()}; Get-Process | Where-Object {$_.MainWindowTitle -ne \"\"} | stop-process"

Note that Stop-Process will actually end the entire process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest