Batch file 批处理文件检查firefox是否打开?
我想写一个批处理文件,每20秒检查一次firefox是否打开,如果打开,则无需执行任何操作。如果firefox关闭,批处理文件需要在特定网页上强制打开。这也需要是一个静默批处理 到目前为止,我已经试过了:Batch file 批处理文件检查firefox是否打开?,batch-file,Batch File,我想写一个批处理文件,每20秒检查一次firefox是否打开,如果打开,则无需执行任何操作。如果firefox关闭,批处理文件需要在特定网页上强制打开。这也需要是一个静默批处理 到目前为止,我已经试过了: @echo off Set WShShell = WScript.CreateObject("WScript.Shell") tasklist /fi "firefox.exe" 2>NUL | find /i /n "firefox.exe">NUL if %ERRORLEVEL
@echo off
Set WShShell = WScript.CreateObject("WScript.Shell")
tasklist /fi "firefox.exe" 2>NUL | find /i /n "firefox.exe">NUL
if %ERRORLEVEL%==1 goto nofirefox
cmd /C start firefox.exe -new-tab "google.com"
你的代码是懒惰的(VBScript行让我大吃一惊),但我知道你要做什么。tasklist
命令缺少一点tasklist/fi“imagename eq firefox.exe”
将在任务列表中搜索firefox。您需要一个循环标记,在20秒的延迟时间内无处ping
试试这个
@echo off
setlocal
:loop
wmic process where name="firefox.exe" get name /format:list 2>NUL | find /i "firefox" >NUL || call :relaunch
ping -n 21 0.0.0.0>NUL
goto loop
:relaunch
rem echo %time% - starting Firefox
start "" firefox.exe -new-tab http://www.google.com/
按N
(或^C
)将退出循环
(在XP中,将CHOICE…和ERRORLEVEL 2行替换为
PING -n 21 127.0.0.1 >nul
if exists stopfile. del stopfile.&goto :eof
然后创建
stopfile.
终止此批处理)到目前为止?echo off Set WShShell=WScript.CreateObject(“WScript.Shell”)任务列表/fi“firefox.exe”2>NUL | find/i/n“firefox.exe”>NUL/if%ERRORLEVEL%==1 goto nofirefox cmd/C start firefox.exe-新标签“google.com”谢谢,但是命令窗口保持打开状态,脚本运行时是否可以隐藏?我从未尝试过,但您可以尝试运行批处理脚本。不过,您所问的可能更适合作为AutoIt脚本,而不是Windows批处理脚本。
PING -n 21 127.0.0.1 >nul
if exists stopfile. del stopfile.&goto :eof