Whenever i run the .bat file it all goes well i choose my time it says it in minutes and all until it comes to confirming your decision and i really have no clue how to fix it for some reason it just goes to :shutdown
Intention: I am using this as a simple little tool when installing games for example if i have to leave steam to download and install a large game overnight i just choose a time and leave it :)
Note: I have no experience with coding ( except changing values on LUA scripts in games ) so an explanation would be
Greatly Appreciated and yes sure i can just use the shutdown command but i wanted to create something a little more fancy
Also if someone could explain to me what the
/s in shutdown
and /a in set timedelay commands do because as i stated i have little to no experience
.
If you can't answer or can't be bothered thank you for your time either way!
Thank you in advance! :)
.
#echo off
cls
title Delayed Shutdown
echo Delayed Shutdown by Martin Angelov
echo Press Any Key To Choose Delay
Pause>NUL
:choosedelay
cls
echo Type in the desired ammount of delay
set /p timedelaysec=
set /a timedelaymin=%timedelaysec% / 60
:confirmation
echo Your current desired shutdown time is:
echo %timedelaysec% Seconds
echo ( %timedelaymin% Minutes )
echo Press 1 to Confirm Shutdown
echo Press 2 to Change Delay
echo press 3 to Exit Program
set /p confirmaation =
if "%confirmaation%" == "1" goto shutdown
if "%confirmaation%" == "2" goto choosedelay
if "%confirmaation%" == "3" goto exit
:shutdown
cls
echo Shutting Down!
echo Delay Chosen:
echo %timedelaysec% Seconds
echo ( %timedelaymin% Minutes )
pause
exit
:exit
cls
echo Exiting Program...
ping 0.0.0.0 -n 2
exit
:Temporary so it doesn't actually enable the shutdown
shutdown /s /t %timedelaysec%
In batch files, it's usually something simple and frustrating.
Try
set /p confirmaation=
(Note that I removed a space before the equals.)
If that fixes your problems, your environment variable wasn't set to any of the three values you checked for and the logic very naturally went line-by-line to :shutdown.
Good luck!
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 made a (very) simple batch file:
#echo off
:start
arp -a | findstr 20-7c-8f-3f-03-9c
cls
if %errorlevel% GEQ 1 (
echo The device is offline
Echo Device is offline at %time% on %date%. >> log.txt
) else (
echo The device is online.
Echo Device is online at %time% on %date%. >> log.txt
)
timeout 3 >nul /nobreak
goto start
While this works fine and dandy, it doesn't work if said device is not listed, ie Phones.
Here's what I mean.
All of the devices connected to my router don't show up in the arp -a output. Say the Mac address of my ipod is 18:E7:F4:86:75:9F. Is there some alternative way to detect if it is on the LAN? Or should I just other software. I like using this, and having it always running in the background. It would be an extremely useful tool. I could tell when my parents get home, or just if anybody I know is at my house. It would serve as a lazy security program. Just thinking of some ideas and potential this could have.
Am I just better off using Nmap?
I figured out a roundabout method to the issue. It doesn't necessarily solve my problem, it just makes my program work. It uses a tool called Wireless Network Watcher, and uses its command line features. I basically print everything on the programs screen to file.txt, and then I scan file.txt for the mac address. It takes around seven seconds to cycle through this whole process, but it gets the job done.
Code:
#echo off
echo gathering info . . .
:start
if exist info.txt del info.txt
wnetwatcher.exe /stext info.txt
:loop
if exist "info.txt" (
goto aaa
)
timeout 2 >nul /nobreak
goto loop
:aaa
cls
find info.txt "18-E3-A4-86-75-9C" >nul
if %errorlevel% GEQ 1 (
color c0
echo.
echo.
echo. Cole's iPod is offline.
) else (
color a0
echo.
echo.
echo. Cole's iPod is online.
)
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Refreshing (7s)
goto start
It would still be nice to have another answer, i.e., why does my ipod not show up?
Sorry for my bad english expression ... i'm not native.
I have searched for an answer for a while ... maybe i'm not doing this right but it seems that my (simple) code is not working for a reason.
As soon as I open the batch programm it shuts without me having the time to read the error message :(
could some one please correct this one ??
I am grateful for any kind of help !
#echo off
color 0a
mode 1000
title THE OFFSWITCH
:start
cls
if %time%== "12:00:00.00" goto :time
echo.
echo IT IS NOT TIME YET : %time%
goto start
:time
echo hello
pause>nul
It is pure luck, if your code works. In the most cases, it will just miss the time, because the loop is not fast enough to get the correct centisecond.
Instead of
if %time%== "12:00:00.00" goto :time
you should use
if "%time%" geq "12:00:00.00" goto :time
(if time is "greater or equal" than...)
Also you should consider to put a delay into the loop, because it eats all of the CPU-Time, it can get, and thus slows down your system. For example timeout /t 1>nul waits for one second.