0

I want to write a batch file to keep checking every 20 seconds if firefox is open, if open then there is no action required. if firefox is closed, the batch file needs to force open it on a certain webpage. this also needs to be a silent batch..

I've tried this so far:

@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" 
4

2 回答 2

0

你的代码很懒(而且 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/
于 2013-03-13T13:34:02.797 回答
0
@ECHO OFF
SETLOCAL
:loop
TASKLIST /fi "imagename eq firefox.exe" |FIND /i "firefox.exe" >nul
IF ERRORLEVEL 1 START firefox.exe -new-tab "google.com"
choice /t 20 /d y /n >NUL
IF ERRORLEVEL 2 GOTO :EOF 
GOTO loop

N(或^C)将退出循环。

(在 XP 中,将 CHOICE... 和 ERRORLEVEL 2 行替换为

PING -n 21 127.0.0.1 >nul  
if exists stopfile. del stopfile.&goto :eof

然后创建stopfile.以终止此批次)

于 2013-03-13T13:46:28.470 回答