How to check if explorer window is open by title in batch?

﹥>﹥吖頭↗ 提交于 2019-12-14 04:13:39

问题


How do I check if an explorer is open or not in batch?

I need to take a screenshot of the directory with a file selected, but only after the window has opened. The window title is always the same.

Thanks

Example:

REM Opening folder with a file selected
START /W EXPLORER /SELECT,\\10.10.10.10\C$\ThisFolder\FileToHighlight.txt
REM Unreliably waiting for window to open
TIMEOUT /T 3 /NOBREAK >NUL
REM Taking screenshot of window with a third-party app
START .\Bin\screenshot-cmd.exe -wt "ThisFolder" -o .\Screenshots\%var%.png

回答1:


Provided there can be no other window with the same title as the opened folder you can use tasklist:

@echo off
rem DON'T ADD A TRAILING \ IN THE PATH!
set folder=d:\path\foldername
explorer "%folder%"
:wait
    timeout 1 >nul
    for %%z in ("%folder%") do (
        tasklist /fi "windowtitle eq %%~nxz" /fi "imagename eq explorer.exe" ^
        | find "explorer.exe" >nul
        if errorlevel 1 goto wait
    )
pause


来源:https://stackoverflow.com/questions/32836825/how-to-check-if-explorer-window-is-open-by-title-in-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!