How to close specified opened folders using batch file

Viewed 952

Since 3 days ago I was trying to close folders using batch file, I've checked multiple sites for the script and none of them worked. For example I open manually without start the folder "CD_Restored" wich is located in C: then I open a batch file inside it to close it, so I wrote:

TASKKILL /F /FI "WINDOWTITLE eq CD_Restored" /IM explorer.exe

and I got this message "information: no in-service task matches the specified criteria"

Also I've wrote:

@echo off
set shell = createobject("wscript.shell") : if shell.appactivate("CD_Restored") then shell.sendkeys "%{F4}"

and didn't work too

2 Answers

You can try with sendkeys.bat:

call sendKeys.bat "CD_Restored" "%{F4}"

but it will work only if the folder window is NOT minimized.

You can follow these steps:

@echo off

cd /d C:\
start C:\Windows\explorer.exe CD_Restored
pause

rem Terminate process:
taskkill /F /FI "WINDOWTITLE eq CD_Restored" /IM explorer.exe > nul
if NOT %errorlevel% EQU 0 (echo It seems that Window title named "CD_Restored" doesn't exist!) else (echo Process successfuly terminated!)
Related