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.
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.