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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like