I'm trying to make an batch file that opens a website for 5 seconds, then closes it an then loop the batch, I got not much Succes, does anyone now how to do this, without letting all te cmd pages on screen(so the batch also closes the cmd after running) I hope someone can help me.
this is the code i got so far, it works but it doesnt close the cmd.exe (Web is the name of the .bat file)
#echo off
start "chrome.exe" "http://www.websitehere. co"
timeout /t 3
taskkill /IM chrome.exe /F
:loop
start /wait Web
goto loop
Greetz Bas
I've tried this code, hope it's good for you:
What i've done is do a while loop, for you to choose how many times will the loop run.
I set the timeout as 10 seconds but you can change it for 5 seconds.
#echo off
set /A x=0
:while
if %x% LEQ 2 (
echo %x%
start /max chrome.exe https://www.google.es
timeout 10
taskkill /F /IM chrome.exe > null
set /A x=%x%+1
goto :while
)
Related
i have a small script that starts waits 60 seconds,starts firefox and runs a imacros script
but the problem is i want to close firefox after 60 seconds and start it again through loop.But what this script does is .It waits for me to close firefox.Then starts 60 seconds timer and then loops the script.
What i want to do is .It should not wait for me to close firefox and directly force closes firefox after 60 seconds and runs in loop
#Echo off
:loop
cls
taskkill /f /im Firefox.exe
cls
taskkill /f /im crashreporter.exe
cls
timeout /T 60
start ""
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m=l4lyt.iim
timeout /T 60
goto loop
What am i doing wrong?why does it waits for me to close firefox instead of directly going to next line.
i.e
timeout /T 60
You had the start command on a separate line from firefox.exe, therefore it launched a command prompt window and then called firefox.exe instead of executing it.
Additionally you don't need to use cls to clear the screen, instead use >nul 2>&1 to suppress output from the taskkill command(s)
Updated script:
#echo off
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m=l4lyt.iim
timeout /T 60
taskkill /f /t /im Firefox.exe /im crashreporter.exe >nul 2>&1
%0
I've tried restarting a program every few minutes with a batch file which looks like the following. However it only opens the .exe a lot of times which causes them to crash. Anyone knows why this problem occurs?
#echo off
:loop
start "programm" "D:\Downloads\programm.exe"
timeout /t 1200 >null
taskkill /f /im "programm" >null
timeout /t 7 >null
goto loop
I hate a short answer, but it's an easy and quick fix. null is nothing, use nul as it's almost certainly skipping the invalid output name.
So the code:
#echo off
:loop
start "programm" "D:\Downloads\programm.exe"
timeout /t 1200 >nul
taskkill /f /im "programm" >nul
timeout /t 7 >nul
goto :loop
taskkill /f /im "programm" >null
Remove the >null and look why it doesn't kill the program.
I am running a command in command prompt and I want to kill it after 15 minutes. I don't care if it is completed or not. I don't want to have any human interaction to kill the running command such as someone has to press CTRL+C to kill it.
Is there a way to do it.
Please note I don;t want to use any third party tools or scripts.
start forfiles /s
timeout /t 5
Taskkill /im forfiles.exe /f
is one way.
Did you mean something like that ?
#echo off
Tracert www.google.com
timeout /t 900 /nobreak >NUL
Taskkill /im cmd.exe /f
Edit : based on the blueray's comment :
how can I put this command in a single line to use in CMD?
Tracert www.google.com & timeout /t 900 /nobreak >NUL & Taskkill /im cmd.exe /f
May be this could help
start your-command-here
ping 127.0.0.1 -n 120 > NUL
taskkill /im cmd.exe /f
Explanation:
start: this command starts executing your command
ping: it pings your local machine(ip : 127.0.0.1) for 120 sec and >NUL redirects the output to nowhere else the output of ping command will be displayed on the cmd screen
taskkill: it is used to kill any task
/im: image name of the process to be terminated. if the command is running on cmd then cmd.exe or any program that you need to kill.
Hope it helps.
Try this, works well for me:
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
#echo off
set _time=0
set _timeout=30
start myprocess.exe
:waitforprocess
set /A _time=_time+1
IF !_time! GTR !_timeout! goto TimedOut
rem TaskList will return the task list of the image as specific
rem or it will return INFO: No tasks are running.... so look for
rem the INFO statement using FindStr. FindStr will return a errorlevel
rem of 0 if it found the string and a 1 if it did not, so use that
rem to work out next steps.
rem -------------------------------------------------------------------
tasklist /NH /FI "IMAGENAME EQ myprocess.exe" | findstr INFO
rem ERRORLEVEL 1 = Did not find the string, so try again.
IF ERRORLEVEL 1 (
timeout /T 1 /NOBREAK > nul
goto :waitforprocess
)
GOTO DONE
:TimedOut
ECHO We timedout so will kill the process
taskkill /FI "IMAGENAME EQ myprocess.exe" /T /F
:Done
echo finished
I have bitlord I want this program to run when i click a batch file and when i don't want this program to run i want to kill it with same batch file. Can anyone please write the script Thanks a lot for giving your time.
I tried it scripting but failed.
If bitlord is not running then this will launch it
If bitlord is running then this will kill it
Change line 2 and line 3 to set the program name and path.
#echo off
set "program=bitlord.exe"
set "folder=c:\program files\bitlord"
tasklist |find /i "%program%" >nul || start "" "%folder%\%program%" & goto :EOF
tasklist |find /i "%program%" >nul && taskkill /f /im "%program%" & goto :EOF
Okay. I think i understand your question now:
#echo off
taskkill.exe /f /im notepad.exe
start calc.exe
The magic is to use the start command which starts a new command asynchronous. Meaning, it doesn't wait for the termination.
Basically I have a simple batch script just now that starts a program multiple times let's call it 1.exe, 1.exe will launch 20 times and then be killed after % amount of seconds (specified by a command line argument).
What I need done is if 1.exe is already running, launch 2.exe instead, if 2.exe and 1.exe are already running launch 3.exe instead and so on.
All the code I really have just now is
Timeout /t 20 /nobreak >nul
echo.
taskkill /F /IM %programname%
echo.
pause >nul
and also the launching of the 1.exe
Any help is appreciated.
The Batch code below launch 2.exe if 1.exe is already running, launch 3.exe if 2.exe is already running and so on:
for /L %%i in (1,1,20) do (
for /F "skip=3" %%e in ('tasklist /fi "imagename eq %%i.exe"') do (
if "%%e" equ "%%i.exe" set lastExe=%%i
)
)
set /A lastExe+=1
%lastExe%.exe