如何使用批处理文件关闭指定打开的文件夹

How to close specified opened folders using batch file

自从 3 天前我尝试使用批处理文件关闭文件夹后,我已经检查了多个站点的脚本并且 none 个有效。例如,我在没有 start 的情况下手动打开位于 C: 中的文件夹 "CD_Restored" 然后我在其中打开一个批处理文件以关闭它,所以我写道:

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

我收到了这条消息 "information: no in-service task matches the specified criteria"

我也写过:

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

也没有用

你可以试试 sendkeys.bat:

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

但只有当文件夹 window 未最小化时它才会起作用。

您可以按照以下步骤操作:

@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!)