How to set RANDOM in a batch file? - windows

So i wrote this batch file.
I need to use some kind of random function to choose between 9 .exe fles.
One of those .exe files is "OPTION1.exe", so i'd like the batch to select from "OPTION2.exe, OPTION3.exe..." etc, which are all located in the same folder as the first one.
I'd like to know if it's possible and how to do it.
Thanks for your time.
#echo off
:loop
TASKKILL /F /IM "Software.exe"
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software
TIMEOUT /T 15
start OPTION1.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe
TIMEOUT /T 400
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO loop

set /a executable=(%random% %% 9) + 1
set "executablename=OPTION%executable%.exe"
echo %executablename%
should show you a random executable name OPTION1.exe .. OPTION9.exe

Well there are a few improvements that you can make to the code you provided. Here is the modified code:
echo off
cls
:loop
TASKKILL /F /IM Software.exe
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software.exe
TIMEOUT /T 15
start OPTION1.exe
start OPTION2.exe
start OPTION3.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe
TIMEOUT /T 400
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO :loop

Related

Batch file that deletes itself and folder that contains it

I'm trying to do the following but deleting the downloaded folder which contains the batch file fails:
NOTE: All exe's, apps, batch file etc. are contained in file.zip.
User downloads file.zip to any directory and unzips.
User runs an exe which is located in the unzipped folder.
This in turn runs two portable apps and some other things.
Once duties are performed, I remote in and run the same exe but this time I select an option that runs a batch file (located in unzipped folder) that starts a 30 second timer then is supposed to stop the apps and delete file.zip and the unzipped folder including the batch file itself.
Below is the batch file:
#echo off
mode con: cols=32 lines=7
color 4f
title
echo 30 Second Delay
echo Close window to abort
echo/
echo/
echo 0%% 100%%
SET /P var= <NUL
set count=0
:loop
PING -n 2 127.0.0.1 >NUL 2>&1
call :printline _
set /a count=count+1
if %count%==30 goto finish
goto loop
:printline
REM Print text passed to sub without a carriage return.
REM Sets line variable in case %1 intereferes with redirect
set line=%1
set /p var=%line%<NUL
exit /b
:finish
cls
color 0f
title Finished
mode con: cols=80 lines=25
echo Do NOT close this window!
echo/
echo Killing processes...
echo/
echo/
echo/
taskkill /t /f /im app1mainprocess.exe >nul
timeout /t 5 >nul
taskkill /t /f /im app2mainprocess.exe >nul
timeout /t 5 >nul
echo Do NOT close this window!
echo/
rem echo Restarting Windows Explorer...
rem timeout /t 10 >nul
rem taskkill /f /im explorer.exe >nul
rem start explorer.exe
echo Do NOT close this window!
echo/
echo Deleteing files and folders...
echo/
rem timeout /t 10 >nul
Set "Folder2Del=%~dp0"
cd ..
IF EXIST "file.zip" DEL "file.zip" /s /q >nul
rem echo %scrptDir%
echo Do NOT close this window!
echo/
echo Still working...
timeout /t 10 >nul
rd %Folder2Del% /s /q
(goto) 2>Nul & RD /S /Q "%Folder2Del%" & exit
The problem I encounter is that the folder never gets deleted. I realize my code is not correct but another reason is because one of the dll files in the unzipped folder is sometimes still in use by the dllhost.exe process.
I'm not sure if it is safe to add a line that kills the dllhost.exe process or not but my code still won't work because I have something wrong with how it deletes the batch file itself and the folder that contains it.
What lines do I need to edit and is it safe to kill dllhost.exe?
According to a link from dbenham
This does the trick:
#Echo off
Echo Ref: "http://www.dostips.com/forum/viewtopic.php?f=3&t=6491"
Set "Folder2Del=%~dp0"
cd "%~d0"
pause
(goto) 2>Nul & RD /S /Q "%Folder2Del%"
Take care the folder containing the batch is deleted
including any other files/folders without any further question!
Ok... I THINK I figured out how to do what I want by trying to delete the dll file, first, before trying to delete the entire directory. The code below looks for the problem dll and tries to delete it. If it still exists, it will try to delete the file every 30 seconds for up to 15 minutes. As soon as the dll gets deleted, the entire folder will also be deleted. If after 15 minutes the dll cannot be deleted, the remaining files in the folder will be deleted.
I still have a small issue. If I add code that kill/restarts Windows Explorer, the folder does not get deleted. Why and is there a workaround?
Below is the latest code:
#echo off
mode con: cols=32 lines=7
color 4f
title
echo 30 Second Delay
echo Close window to abort
echo/
echo/
echo 0%% 100%%
SET /P var= <NUL
set count=0
:loop
PING -n 2 127.0.0.1 >NUL 2>&1
call :printline _
set /a count=count+1
if %count%==30 goto finish
goto loop
:printline
REM Print text passed to sub without a carriage return.
REM Sets line variable in case %1 intereferes with redirect
set line=%1
set /p var=%line%<NUL
exit /b
:finish
cls
color 0f
title Uninstall
mode con: cols=80 lines=25
echo Do NOT close this window!
echo/
echo Killing processes...
tasklist /fi "imagename eq app1mainprocess.exe" |find ":" > nul
if errorlevel 1 taskkill /t /f /im "app1mainprocess.exe" > nul
tasklist /fi "imagename eq app2mainprocess.exe" |find ":" > nul
if errorlevel 1 taskkill /t /f /im "app2mainprocess.exe" > nul
timeout /t 5 >nul
rem echo Do NOT close this window!
rem echo/
rem echo Restarting Windows Explorer...
rem timeout /t 10 >nul
rem taskkill /f /im explorer.exe >nul
rem start explorer.exe
echo/
echo Deleteing file.zip if it exists...
timeout /t 5 >nul
Set "Folder2Del=%~dp0"
cd ..
IF EXIST "file.zip" DEL "file.zip" /s /q >nul
rem echo %Folder2Del%
rem Loops for 30 times in 30 second intervals (Total 15 minutes) to confirm deletion. Loop will exit after 30 loops and move on if dll cannot be deleted.
for /l %%i in (1,1,30) do (
del "%Folder2Del%name*.dll"
if not exist "%Folder2Del%name*.dll" goto Folder2Del
echo/
echo File locked! May take up to 15 minutes to delete.
echo Will stop trying 15 minutes after first attempt.
timeout /t 30 >nul
)
:Folder2Del
echo/
echo Attempting to delete the Connector folder and it's contents...
timeout /t 5 >nul
rd "%~dp0" /s /q & exit

Can you put goto and if then into one line?

I am trying to put the goto and the if then command in the same line because so I don't have to make a another BAT files to get the job done.
Here an example of the code that I am makeing so far:
#echo off
SET _cliportaskkill=0
SET _startffox=0
If "%_cliportaskkill%"=="2" goto everything
If "%_cliportaskkill%"=="1" goto cliponly
If "%_cliportaskkill%"=="0" goto taskkillonly
:cliponly
echo|set /p=username#email.com|clip
EXIT
:taskkillonly
TASKKILL /F /T /IM Greenshot.exe & TASKKILL /F /T /IM iprntctl.exe & TASKKILL /F /T /IM iprntlgn.exe & TASKKILL /F /T /IM smax4pnp.exe & TASKKILL /F /T /IM ZenNotifyIcon.exe & TASKKILL /F /T /IM ZenUserDaemon.exe & TASKKILL /F /T /IM RAVBg64.exe & TASKKILL /F /T /IM nwtray.exe & TASKKILL /F /T /IM RtkNGUI64.exe & TASKKILL /F /T /IM BingSvc.exe & TASKKILL /F /T /IM Spotify.exe & TASKKILL /F /T /IM SpotifyWebHelper.exe & TASKKILL /F /T /IM FacebookGameroom.exe & TASKKILL /F /T /IM "Facebook Gameroom Browser.exe" & TASKKILL /F /T /IM zapp.exe & TASKKILL /F /T /IM steamwebhelper.exe & TASKKILL /F /T /IM Steam.exe & TASKKILL /F /T /IM lync.exe
EXIT
:everything
echo|set /p=username#email.com|clip
TASKKILL /F /T /IM Greenshot.exe & TASKKILL /F /T /IM iprntctl.exe & TASKKILL /F /T /IM iprntlgn.exe & TASKKILL /F /T /IM smax4pnp.exe & TASKKILL /F /T /IM ZenNotifyIcon.exe & TASKKILL /F /T /IM ZenUserDaemon.exe & TASKKILL /F /T /IM RAVBg64.exe & TASKKILL /F /T /IM nwtray.exe & TASKKILL /F /T /IM RtkNGUI64.exe & TASKKILL /F /T /IM BingSvc.exe & TASKKILL /F /T /IM Spotify.exe & TASKKILL /F /T /IM SpotifyWebHelper.exe & TASKKILL /F /T /IM FacebookGameroom.exe & TASKKILL /F /T /IM "Facebook Gameroom Browser.exe" & TASKKILL /F /T /IM zapp.exe & TASKKILL /F /T /IM steamwebhelper.exe & TASKKILL /F /T /IM Steam.exe & TASKKILL /F /T /IM lync.exe
EXIT
===================================================================================================================
#echo off
If "%_startffox%"=="1" goto newwindow
If "%_startffox%"=="0" goto newtab
:newwindow
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe "https://www.outlook.com/" "http://everybodyedits.com/" "http://www.kongregate.com/accounts/username/recently-played"
EXIT
:newtab
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe -new-tab "https://www.outlook.com/" -new-tab "http://everybodyedits.com/" -new-tab "http://www.kongregate.com/accounts/username/recently-played"
EXIT
Whcih is used for this BAT file:
Old verson
#echo on
START "taskkilling and cliping" CMD /c "#echo off & echo|set /p=username#email.com|clip & TASKKILL /F /T /IM Greenshot.exe & TASKKILL /F /T /IM iprntctl.exe & TASKKILL /F /T /IM iprntlgn.exe & TASKKILL /F /T /IM smax4pnp.exe & TASKKILL /F /T /IM ZenNotifyIcon.exe & TASKKILL /F /T /IM ZenUserDaemon.exe & TASKKILL /F /T /IM RAVBg64.exe & TASKKILL /F /T /IM nwtray.exe & TASKKILL /F /T /IM RtkNGUI64.exe & TASKKILL /F /T /IM BingSvc.exe & TASKKILL /F /T /IM Spotify.exe & TASKKILL /F /T /IM SpotifyWebHelper.exe & TASKKILL /F /T /IM FacebookGameroom.exe & TASKKILL /F /T /IM "Facebook Gameroom Browser.exe" & TASKKILL /F /T /IM zapp.exe & TASKKILL /F /T /IM steamwebhelper.exe & TASKKILL /F /T /IM Steam.exe & TASKKILL /F /T /IM lync.exe"
START "start new firefox in three new tabs" CMD /c "#echo off & CD /D "C:\Program Files (x86)\Mozilla Firefox" & firefox.exe "https://www.outlook.com/" "http://everybodyedits.com/" "http://www.kongregate.com/accounts/username/recently-played""
So I am trying make a BAT file that have options that I can use for my new verson that I use when I log on to the computer.
So far I try testing the one of code through a different BAT file so here what I have so far:
SET _startffox=0
CHOICE /C wt /m "w open new window, t open new tab"
IF errorlevel 2 set _startffox=0 & goto line
IF errorlevel 1 set _startffox=1 & goto line
:line
pause & echo %_startffox%
(echo on & (If "%_startffox%"=="1" goto newwindow); (If "%_startffox%"=="0" goto newtab); (:newwindow & ECHO "go to new window firefox" & ECHO "Hi windows" & pause & EXIT); (:newtab & ECHO "go to new tabs firefox" & ECHO "Hi tabs" & pause & EXIT))
pause
so far it does not work the way I wahntd to work.
#echo off
setlocal
SET "_cliportaskkill=0"
SET "_startffox=0"
If "%_cliportaskkill%"=="2" call :everything
If "%_cliportaskkill%"=="1" call :cliponly
If "%_cliportaskkill%"=="0" call :taskkillonly
If "%_startffox%"=="1" call :newwindow
If "%_startffox%"=="0" call :newtab
EXIT /B
:cliponly
echo|set /p=username#email.com|clip
EXIT /B
:taskkillonly
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:everything
echo|set /p=username#email.com|clip
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:newwindow
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
"https://www.outlook.com/"^
"http://everybodyedits.com/"^
"http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
:newtab
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
-new-tab "https://www.outlook.com/"^
-new-tab "http://everybodyedits.com/"^
-new-tab "http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
Can you put goto and if then into one line?
Yes.
Labels though need to be at the start of a line and can be preceded
by spaces used for indenting.
Advise you use call instead of goto in many instances as it will
give good program flow as call goes to the label and then returns
back to the line of the caller. Using goto goes to the label and
then you may need to use goto again to go somewhere else and thus
you go all over and may eventually may become lost. So using call
allows all the main code to be grouped together and call labels as
needed.
taskkill can handle multiple images in the one process thus may be
more efficient.
Use ^ to continue the command over to the next line to line up the
arguments vertically. Can improve readability and maintenance.
Use of EXIT /B can exit a label or the script.
Use of EXIT closes the interpreter which is usually undesirable
for a script.
Be free to update the code using CHOICE or any other new ideas
you may have.
Example of indented label.
#echo off
if not "%~1" == "" call :level0 %*
exit /b
:level0
echo test indented label
:level1
echo "%~1"
shift
if not "%~1" == "" goto :level1
echo done
exit /b
Call the example script with arguments i.e. main.cmd 1 2 3. The interpreter will find :level1 even though it is indented.
Still haven't figure out how to put in one line and updated michael_heath code with a litte bit of mine:
#echo on
setlocal
CHOICE /C ectfx /m "e do everything, c clip only, t taskkill only, f skip this, x close this"
If errorlevel 5 EXIT /B
If errorlevel 4 goto :choiceff
If errorlevel 3 call :taskkillonly
If errorlevel 2 call :cliponly
If errorlevel 1 call :everything
:choiceff
CHOICE /C wtx /m "w open new window, t open new tab, x close this"
If errorlevel 3 EXIT /B
If errorlevel 2 call :newtab
If errorlevel 1 call :newwindow
EXIT /B
:cliponly
echo|set /p=username#email.com|clip
EXIT /B
:taskkillonly
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:everything
echo|set /p=username#email.com|clip
TASKKILL /F /T^
/IM Greenshot.exe^
/IM iprntctl.exe^
/IM iprntlgn.exe^
/IM smax4pnp.exe^
/IM ZenNotifyIcon.exe^
/IM ZenUserDaemon.exe^
/IM RAVBg64.exe^
/IM nwtray.exe^
/IM RtkNGUI64.exe^
/IM BingSvc.exe^
/IM Spotify.exe^
/IM SpotifyWebHelper.exe^
/IM FacebookGameroom.exe^
/IM "Facebook Gameroom Browser.exe"^
/IM zapp.exe^
/IM steamwebhelper.exe^
/IM Steam.exe^
/IM lync.exe
EXIT /B
:newwindow
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
"https://www.outlook.com/"^
"http://everybodyedits.com/"^
"http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
:newtab
CD /D "C:\Program Files (x86)\Mozilla Firefox"
firefox.exe^
-new-tab "https://www.outlook.com/"^
-new-tab "http://everybodyedits.com/"^
-new-tab "http://www.kongregate.com/accounts/username/recently-played"
EXIT /B
Remove the VAR cliportaskkill and startffox from the code and a litte bug where pressing t to taskkill only after it finish the code it go to the next errorlevel and call the :cliponly code before it move on to the next choice command (this where I put an & goto :label to stop this bug but may break this BAT file when put into one line.)
P.S. In the near future I am thinking I could put the cliportaskkill and startffox VAR back in so that I can use it for parallel codes or two instances without waiting for the other codes to finish (without doing in another BAT files as well.)
I'ev set echo to on and here the output of the codes.
>setlocal
>CHOICE /C ectfx /m "e do everything, c clip only, t taskkill only, f skip this, x close this"
e do everything, c clip only, t taskkill only, f skip this, x close this [E,C,T,F,X]?T
>If errorlevel 5 EXIT /B
>If errorlevel 4 goto :choiceff
>If errorlevel 3 call :taskkillonly
>TASKKILL /F /T /IM Greenshot.exe /IM iprntctl.exe /IM iprntlgn.exe /IM smax4pnp.exe /IM ZenNotifyIcon.ex
e /IM ZenUserDaemon.exe /IM RAVBg64.exe /IM nwtray.exe /IM RtkNGUI64.exe /IM BingSvc.exe /IM Spotify.exe /IM SpotifyWebHelper.exe /IM F
acebookGameroom.exe /IM "Facebook Gameroom Browser.exe" /IM zapp.exe /IM steamwebhelper.exe /IM Steam.exe /IM lync.exe
ERROR: The process "Greenshot.exe" not found.
ERROR: The process "iprntctl.exe" not found.
ERROR: The process "iprntlgn.exe" not found.
ERROR: The process "smax4pnp.exe" not found.
ERROR: The process "ZenNotifyIcon.exe" not found.
ERROR: The process "ZenUserDaemon.exe" not found.
ERROR: The process "RAVBg64.exe" not found.
ERROR: The process "nwtray.exe" not found.
ERROR: The process "RtkNGUI64.exe" not found.
ERROR: The process "BingSvc.exe" not found.
ERROR: The process "Spotify.exe" not found.
ERROR: The process "SpotifyWebHelper.exe" not found.
ERROR: The process "FacebookGameroom.exe" not found.
ERROR: The process "Facebook Gameroom Browser.exe" not found.
ERROR: The process "zapp.exe" not found.
ERROR: The process "steamwebhelper.exe" not found.
ERROR: The process "Steam.exe" not found.
ERROR: The process "lync.exe" not found.
>EXIT /B
>If errorlevel 2 call :cliponly
>echo | set /p=username#email.com | clip
>EXIT /B
>If errorlevel 1 call :everything
>CHOICE /C wtx /m "w open new window, t open new tab, x close this"
w open new window, t open new tab, x close this [W,T,X]?
As you can see after the taskkill block it go to the next block which is the clip code before going to the next CHOICE commmand (for some reason it does not go to the next block of codes.)
I've press T for this one
>If errorlevel 3 EXIT /B
>If errorlevel 2 call :newtab
>CD /D "C:\Program Files (x86)\Mozilla Firefox"
>firefox.exe -new-tab "https://www.outlook.com/" -new-tab "http://everybodyedits.com/" -new-tab "
http://www.kongregate.com/accounts/username/recently-played"
>ECHO newtab!
newtab!
>pause
Press any key to continue . . .
>EXIT /B
>If errorlevel 1 call :newwindow
>CD /D "C:\Program Files (x86)\Mozilla Firefox"
>firefox.exe "https://www.outlook.com/" "http://everybodyedits.com/" "http://www.kongregate.com/a
ccounts/username/recently-played"
>ECHO newwindow!
newwindow!
>pause
Press any key to continue . . .
I've add an echo and pause to test if it do the same for this CHOICE command and it start the next block of code after it finished the the previous code. I've tested this in a test file where I used some CHOICE, If errorlevel, calling and goto commands and same bugs happened in the test file.

CMD prompt - bat file - Taskkill command ignores start /wait

Here's my script in my bat file:
cd "C:\Program Files (x86)\Steam\Steamapps\common\F13game\"
Start F13theGameRemap.exe
cd "C:\Program Files (x86)\Steam\steamapps\common\F13Game\SummerCamp\Binaries\Win64\"
Start /WAIT SummerCamp.exe
Start /WAIT Taskkill /f /im F13theGameRemap.exe
exit
All I want is to run the first program, then the 2nd. When the 2nd program "summercamp.exe" exits, i want the first program "F13thegameremap.exe" to exit.
The way this script works now is that Taskkill immediately ignores the start /wait command of summercamp.exe and closes F13theGameRemap.exe immediately.
How do I fix this?
Something like this:
#Echo off
Cd /D "C:\Program Files (x86)\Steam\Steamapps\common\F13game\"
Start F13theGameRemap.exe
Cd /D "C:\Program Files (x86)\Steam\steamapps\common\F13Game\SummerCamp\Binaries\Win64\"
Set "App2=SummerCamp.exe"
Start /WAIT %App2%
:loop
Timeout /t 1 >NUL
tasklist.exe /FI "ImageName eq %App2%" /NH |find /i "%App2%" >NUL && Goto :loop
Start /WAIT Taskkill /f /im F13theGameRemap.exe
The :loop will check with 1 second delay if %App2% aka SummerCamp.exe is still running.

Restart terminal application with a batch file

I need a .bat file that will close and re-open start.cmd (C:\Users\Jake\Desktop\PocketMine-MP\start.cmd) <-- that's the file location. I need it to close and re-open every 75 min. The terminal has to close it can't stay open and launch another all I've gotten so far is:
#echo off
:loop
start "start.cmd" "C:\Users\Jake\Desktop\PocketMine-MP\start.cmd
timeout /t 20
taskkill /f /im "start.cmd" >nul
goto loop
Its starting the terminal every 20 seconds like I want it too but its not closing the old one.
If anyone can help it would assist me and my small network greatly.
Rename start.cmd to bat_start.cmd then try the following.
#echo off
:loop
start "bat_start.cmd" "C:\Users\Jake\Desktop\PocketMine-MP\bat_start.cmd"
timeout /t 20
taskkill /f /fi "windowtitle eq bat_start.cmd*" /im "cmd.exe" >nul
goto loop
If you use same file for control the loop and start file again, then it's fall in recursion. Following example work for me,
#echo off
:loop
start "test2" "C:\test2.bat"
timeout /t 60
taskkill /f /fi "windowtitle eq test2*" /im "cmd.exe" >nul
goto loop
test2 file
#echo off
echo "start job here"
:: Do your work here
pause :: remove the pause, it's just for simulating
exit
You can use the TimeCommander plugin. Set to run a restart command every 75 minutes.

Open several tabs in one Internet Explorer window

I am trying to create a batch script that opens up 2 websites in iexplorer (I need to use IE).
Problem is, the urls are opened in separate IE windows.
Is it possible to just have 2 tabs in 1 window?
taskkill /im iexplore.exe /f
taskkill /t /f /im chrome.exe
taskkill /t /f /im communicator.exe
ping 127.0.0.1 -n 4
start iexplore.exe http://site1
start iexplore.exe http://site2
start communicator.exe
Use VBScript code to start a new InternetExplorer.Application and open the tabs using navigate2 method with navOpenInNewTab = 2048 flag:
#echo off
findstr /r /c:"^::[^ ]" "%~dpnx0" > "%temp%\openIEtab.vbs"
cscript //b //nologo "%temp%\openIEtab.vbs"
del "%temp%\openIEtab.vbs"
::set IE = CreateObject("InternetExplorer.Application")
::IE.visible = true
::IE.navigate2 "google.com"
::IE.navigate2 "bing.com", 2048
There are also powershell solutions (example).
Try adding a timeout right after the first website you're trying to open, like this. Timeout will wait whatever amount of seconds you set after the /T which might be what you're trying to accomplish with the ping command, unless you need to ping a specific address everytime.
taskkill /im iexplore.exe /f
taskkill /t /f /im chrome.exe
taskkill /t /f /im communicator.exe
ping 127.0.0.1 -n 4
start iexplore.exe http://site1
TIMEOUT>NUL /T 3 /NOBREAK
start iexplore.exe http://site2
start communicator.exe

Resources