Is it possible to close Windows Explorer from CMD? I have a batch that does this: it will change directory, open explorer in this folder, than run a program. After the user closes the program the batch should close the explorer (or all explorers opened), continue on next folder (cd folder), run the same program in this folder and so on. Till the last folder is processed.
Close the explorer windows by killing the explorer process (note that this may do more than just kill the windows, but it will definitely do that):
for example, use win+r and try this
cmd /c "taskkill /f /im explorer.exe && start explorer"
If you kill explorer without restarting it, use Ctrl+shift+Esc to pull up the taskmanager and start a new task "explorer".
Not from a batch file unless you want to write your own command line application that opens up a windows explorer window, and (this is the key part) somehow knows the window handle of that explorer window, so it can post a WM_CLOSE
message to it, which basically simulates someone closing that window.
How you would determine "all the explorer windows that got opened" would be that instead of just starting explorer.exe
instances from a command line you would do it from your own application.
I think that determining the window handle (HWND
in win32 api terms) and posting a close message would be better than trying to track process handles and terminating explorer process instances, since that could cause some side effects beyond those that you'd want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With