I am new to this and I am trying a basic example I saw on Youtube:
#echo off
echo this little program helps you to refresh a website
pause
cls
echo but first we have to do some preferences
pause
cls
echo please enter the website name here
set /p website=
cls
echo please enter the time between refreshes
set /p time=
cls
echo Set limited or unlimited refresh
set /p refresh=
if'%refresh%'=='1' goto :once
if'%refresh%'=='0' goto :unlimited
cls
:once
cls
echo Preferences finished
pause
timeout /t %time% /nobreak
start %website%
exit
:unlimited
cls
echo Preferences finished
pause
:again
timeout /t %time% /nobreak
start %website%
goto :again
This code is supposed to ask a user for a website and a refresh time and it will refresh that website by reopening it in IE (Internet Explorer), however I have 2 problems with this:
The loop does not work if I enter 0 or '0' it will only execute once and exit the .bat
Is there a way to refresh a page without reopening the page in a new tab, for example just refresh the current tab ?
There are some syntax errors in your script.
EXIT command
EXIT exits the script. You may want to change that to something else.
IF Statement
if'%refresh%'=='1' goto :once
is slightly incorrect, as there is a missing space between if and the comparee. In addition, using double quotes ensure it to successfully compare with values including spaces.
if "%refresh%"=="1" goto :once
Undefined Input
If variable %refresh% is not 1 or 0, it goes to :once and execute the code there.
Refreshing Webpage
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Chrome")
WshShell.SendKeys "{F5}"
Save this script as Refresh.vbs and put it in the same folder as the batch file.
Then, when you want to refresh the webpage, do cscript //nologo Refresh.vbs.
Related
#echo off
cls
echo Hello, there! Today is
date /t
echo and the current time is
time /t
echo I'm so glad to meet you. My name is Hal 10000.
set /p name=What's your name?
cls
echo Well hello, %name%
echo Hey, %name%, & set /p "age"="how old are you in years?"
echo Well that's just great! I'm actually 115 today.
echo I look pretty good, huh!?
echo Well, gotta go, by!
exit
Looks like you need a pause command. Your code is executing correctly but there is nothing stopping the code from exiting before you see your results.
#Echo off
Echo This message will not be displayed.
cls
Echo This message will be displayed.
pause
exit
Adding a pause before the exit will show your results until a button is pressed.
Hi im not really good in writing batch scripts, im new to this, i really need help,
The script i have needs to do an unattended installation,
i got that part to work, what i need is to show a progress bar for the users to see the progress of the installation,
the script i have is below:
#echo off
echo --------------------------------------------------------------
echo --------------------------------------------------------------
echo Software is installing......
echo.
echo please wait, do not close!!
echo.
C:\files\gw18\win32\install.bat /unattended
cls
i found this really cool progress bar script, i need help to make it work with the above
#echo off
setlocal EnableDelayedExpansion
set Counter=0
set Schalter=2
set Width=0
:1
title Animation Box - Installation
set /a Counter=%Counter% + 1
set /a Display=%Counter% / 2
FOR /L %%A IN (1,1,%Display%) DO (
set Display=!Display!²
)
cls
echo Progress... %Counter%%%
echo ²!Display:~2,47!
ping localhost -n 1 >nul
if "%Counter%" == "100" goto :1-End
goto :1
:1-End
echo.
echo Installation complete.
pause >nul
Or any progress bar code that will work
Thank you in advance :)
What I would recommend doing for the progress bar script, is make it so that the installer outputs a text file every time it completes a task. For example, when it completes MOVE file.exe "C:\Program Files\Application", echo EXE Move Completed. > 1.txt.
Then, the progress bar script would constantly watch for those files, then update the progress bar accordingly. Example:
:watch1
if exist 1.txt goto update1
goto watch1
:update1
cls
echo Progress: 0========== 0
DEL 1.txt
goto watch2
:watch2
if exist 2.txt goto update2
goto watch2
And so on.
So every time the progress bar script finds a new file outputted by the installer, it adds a little bit more to the progress bar.
Hope this helped.
I used the code provided in the best answer in this thread: Need auto-restart script in batch for minecraft server
However, I'm not sure when the choice function is supposed to run.
Furthermore, I'd rather not have a choice option. I'd like the server just to give a 60 second heads up that it's going to restart and then execute the restart.
Any help would be appreciated!
Here's the code from the previous answer:
#echo off
title minecraft-server-1.8.3
color 0A
prompt [server]:
cls
:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls
:choice
set /P a=do you want to restart[Y/N]?
if /I "%a%" EQU "Y" goto :restart
if /I "%a%" EQU "N" goto :stop
goto :choice
:restart
cls
echo server will restart
TIMEOUT /T 5
cls
goto :start
:stop
cls
echo closing server
TIMEOUT /T 5
exit
Welcome to stack overflow.
As #Mofi mentioned in a comment, you can use TIMEOUT to create wait statement
The script you might want would look something like this:
:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls
REM I recommend NOT using TIMEOUT /T for the main wait, this way you can skip it and initiate a restart immediately
TIMEOUT 10720
REM 3 hours minus 60 seconds to allow for 60 second restart notification
cls
echo server will restart
TIMEOUT /T 60
cls
goto :start
(Since you seem to be somewhat new to batch, REM is used to comment out lines)
To answer your question surrounding why the :choice section is a thing:
It is initiated after the :start section, allowing you to either (Y) restart, or (N) stop the server
I looked for quite a while and couldn't find a good solution to my problem. I want a batch program to "look" in a .txt file for the command "" and if that word is in it, then to execute a different command. If the command existed, I would want to do something like set %textfile%=text.txt and if that worked I would then do if %textfile%==update goto update which would be an easy way to start an automatic update if this was in a loop. So basically, is there a command that sets a text file in %text%? This is the code that I am trying to add this into:
#echo off
color 0f
:start
echo Welcome to Master control pannel
ping 127.1 -n 4 >nul
cls
:options
cls
echo What would you like to do first? (Type the number of the operation you want to start)
echo.
ping 127.1 -n 2 >nul
echo 1. Run a command off of all computers
::(I want to run a command by sending a message to a text file but want recieving computor to be able to read it and execute it, how could I read the command and then do what it say, for example, if the command says "echo Hello" I would want recieving computor to say "Hello" )
echo 2. Stops the current command
echo 3. List all computers
echo 4. Open remote shutdown program
echo 5. Delete a computor (in progress)
echo 6. (Unfinished)
echo 7. (Unfinished)
echo 8. (Unfinished)
echo 9. (Unfinished)
echo 10. Exit
set /p choose=(1-9):
if %choose%==1 goto o1
if %choose%==2 goto o2
if %choose%==3 goto o3
if %choose%==4 goto o4
if %choose%==5 goto o5
if %choose%==6 goto close
if %choose%==7 goto close
if %choose%==8 goto close
if %choose%==9 goto close
if %choose%==10 goto o10
goto options
:close
cls
goto start
:o1
echo Stopping current command
del command.txt
echo. 2>command.txt
echo Command stopped!
pause
cls
goto start
I would greatly appreciate some help or comments to what I could do or add to this. Thanks!
Not an answer but several hints.
a variable can hold only single lines not a whole file.
if you want to get the first line of a file into a var use `Set /P "var="
set %textfile%=text.txt would store test.txt literally into a var whose name is the content of the var textfile.
you are mixing goto o1 and :01 with the label
`
My batch script does the following:
user types in username and is added to a variable
trick to ask for password (hides input from user) and adds to variable
checks username and password authentication for domain GROUP using "net user" command
If user is found in set group, continue to map drive.
If user is not part of group restart at beginning
This script works when the username is found.
This script works when a username is found in a group
The problem is if the username is NOT FOUND.
When the user is NOT FOUND, it reports the "More help is available by typing NET HELPMSG 2221."
It just sits there and does not continue to prompt or anything.
I echoed the errorlevel and it comes out to 0, and reports the 0. However it still just sits there never reaching command prompt or going where the GOTO tells it.
I have put in errorlevels and I am unsure why it is stuck after the error message and does not continue. It is as if the batch script is not releasing from somewhere.
#echo off
:Question
Echo.
Echo.
SET /P HelperName=Enter Witness' Name:
Echo.
If %HelperName% EQU %Username% GOTO SameUserName
cls
echo hP1X500P[PZBBBfh#b##fXf-V#`$fPf]f3/f1/5++u5>%temp%\ftp.com
set /p password=What is your password? <nul
for /f "tokens=*" %%i in ('%temp%\ftp.com') do set "password=%%i"
del %temp%\ftp.com
cls
set i=0
set group=WGD
set user=%HelperName%
echo Checking if %user% is member of %group%...
for /f %%f in ('"net user %user% /domain | findstr /i %group%"') do set /a i=%i%+1
if %i% gtr 0 (goto :member)
:nomember
echo %user% is not member of %group% Please Try Again
goto :question
:member
net use L: \\10.10.10.10\foldernamehere\TEMP /user:wgd\%helpername% %password%
if [%errorlevel%]==[0] goto deletedrive
goto error
:deletedrive
net use /delete L:
goto start
It is as if the script in still in another function.
Well it seems like I was not waiting long enough for the message to finish. It hangs for a bit, then continues on through the script. The wait however for the help message to clear is a little long, if you know how to clear faster please let me know.