How do I start Minecraft and Valorant from a batch file? - batch-file

Last night, I decided to try coding a batch file. I used some references and some online walkthroughs and ended up making the following program.
echo off
Title Log into CMD
:home
color 0A
echo ==================
echo.
echo [1] Log In
echo [2] Exit
set /p login=
if %login%==1 goto 1
if %login%==2 goto 2
goto error
:1
echo.
echo ==================
echo.
set and=if
set /p name=Enter your name:
set /p pass=Enter your password:
if %name%==Bob %and% %pass%==***** echo Welcome, Omid
if not %name%==Bob goto no
if not %pass%==***** goto no
goto GameMenu
:no
echo You're not Bob!
pause
echo Goodbye!
pause
exit
:2
exit
:error
echo You have to select a valid option!
:GameMenu
Title Game Menu
echo.
echo ==================
echo.
echo [1] Minecraft
echo [2] krunker.io
echo [3] Valorant
set /p gc=Enter the number of the game you would like to play:
if %gc%==1 goto Minecraft
if %gc%==2 goto krunker
if%gc%==3 goto Valorant
goto error
:Minecraft
start MinecraftLauncher.exe
exit
:krunker
start https://www.krunker.io/
exit
:Valorant
start RiotClientServices.exe
exit
This program is a simple one that you log into with a username and password, which then leads to a directory of games to open. The krunker.io works, but I wasn't sure on how to call Minecraft and Valorant. The processes that open up the games are what I called. For example, MinecraftLauncher.exe is the name of the process that would launch Minecraft. When I choose Minecraft from the menu, it gives the error message 'Windows cannot find "MinecraftLauncher.exe" Make sure you typed the name correctly, and then try again.` This is strange given this is the literal name of the launcher. I was wondering if anyone with a bit more experience could help me out.

You have to go thru the path to initialize the application. Here's a step-by-step:
cd/
cd "Program Files (x86)/Minecraft"
start MinecraftLauncher.exe
You have to ensure that cmd is at c:\ using cd/, then go to launcher file location and starts it. You can do that by using start/d.
So, here's your code:
#echo off
Title Log into CMD
:home
color 0A
echo ==================
echo.
echo [1] Log In
echo [2] Exit
set /p login=
if %login%==1 goto 1
if %login%==2 goto 2
goto error
:1
echo.
echo ==================
echo.
set and=if
set /p name=Enter your name:
set /p pass=Enter your password:
if %name%==Bob %and% %pass%==***** echo Welcome, Omid
if not %name%==Bob goto no
if not %pass%==***** goto no
goto GameMenu
:no
echo You're not Bob!
pause
echo Goodbye!
pause
exit
:2
exit
:error
echo You have to select a valid option!
:GameMenu
Title Game Menu
echo.
echo ==================
echo.
echo [1] Minecraft
echo [2] krunker.io
echo [3] Valorant
set /p gc=Enter the number of the game you would like to play:
if %gc%==1 goto Minecraft
if %gc%==2 goto krunker
if%gc%==3 goto Valorant
goto error
:Minecraft
cd/
start/d "C:\Program Files (x86)\Minecraft" MinecraftLauncher.exe
exit
:krunker
start https://www.krunker.io/
exit
:Valorant
cd/
start/d "C:\Program Files (x86)\*VALORANT LAUNCHER FOLDER*" RiotClientServices.exe
exit
And your login system is broken. If you put any key other than 1 or 2, you go direct to :GameMenu, it can be easily solved by putting :error at the very end of the file or using a goto home before echo You have to select a valid option!
Hope this helps you.

Related

Is there a way I could check the status of a Pi-Hole through a batch script

I'm trying to make a script that can help me remotely monitor my Pi-Hole through batch, and I want to add a feature that checks if the Pi-Hole is actually on, possibly by using ping, but I can't figure out how to.
Current Code:
ECHO OFF
ECHO CHECKING PI-HOLE STATUS
CLS
:MENU
ECHO.
ECHO ........................
ECHO SSH servers
ECHO ........................
ECHO.
ECHO 1 - Pi-Hole Console
ECHO 2 - Pi-Hole Network Interface
ECHO E - EXIT
ECHO.
SET /P M=Type 1 - 2 then press ENTER:
IF %M%==1 GOTO WEB1
IF %M%==2 GOTO WEB2
IF %M%==E GOTO EOF
IF %M%==e GOTO EOF
REM ------------------------------
REM SSH Server details
REM ------------------------------
:WEB1
CLS
call ssh pi#192.168.1.10
GOTO MENU
:WEB2
CLS
start opera pi-hole/admin
GOTO MENU
:EOF
taskkill /f /im cmd.exe

trying to make an "OS" in batch

#echo off
:load
rem imitation of loading the os
color 70
ver
title boot
echo please wait...
ping localhost -n 3 >nul
cls
systeminfo
rem in here user types name he wants to be his account name
:login
title login
cls
date
cls
echo welcome to windows 71
echo before we bigen please type your name
set /P_name=here:
if %name%=admin goto admin
if not goto ms
rem ms=menu start
:ms
echo %time%
echo hello %name%
echo type HELP for list to commands
set /P_command=here:
if %command%=help goto help
if %command%=exit goto exit
if %command%=calendar goto cal
if not goto wc
rem wc=wrong command
:admin
echo hello %name% to the admin panel
echo type HELP for list to commands
set /P_command=here:
if %command%=help goto help
if %command%=exit goto exit
if %command%=calendar goto cal
So the problem is that it crashes after the :LOGIN part and I don't know what to do!
I'm trying to make an OS batch (something like MS-DOS), but it crashes after the "login" part.
I tried everything I could think of and it didn't work, also I want to make a save file so users can set a password for their "account".
As mentioned in above comments, you need to correctly use your variables, you can however use choice instead of set /p for your commands.
#echo off
:load
rem imitation of loading the os
color 70
ver
title boot
echo please wait...
timeout /t 3 >nul
cls
systeminfo
rem in here user types name he wants to be his account name
:login
title login
cls
date /t
timeout /t 2>nul
cls
echo welcome to windows 71
echo Before we begin please type your name
set /P "_name=here:"
if /i "_%name%"=="admin" goto admin
rem ms=menu start
:ms
echo %time%
echo hello %_name%
echo type HELP for list to commands
CHOICE /C HEC /M "Press H for Help, E to exit C for Calender."
goto opt%errorlevel%
:admin
echo hello %_name% to the admin panel
echo type HELP for list to commands
CHOICE /C HEC /M "Press H for Help, E to exit C for Calender."
goto opt%errorlevel%
:opt1
echo Help stuff goes here
goto :eof
:opt2
exit
:opt3
echo Calenders stuff goes here
Some things to note. You do not require to goto ms is the user is not admin as the statement for not being admin will not be met, we will automatically faal through into the ms label.
Notice where the problems were in your code. i.e if %name%=admin should be if "%_name%"=="admin" with double equal sign and the underscore in the name. It is also double quoted to ensure that we do a match without unwanted whitespace. Lastly /I option to catch ADMIN in any case.
See if /?, choice /? from command line for more help around these functions.
Okay this code is quite wrong.
I fixed it.
#echo off
:load
rem imitation of loading the os
color 70
title boot
echo please wait...
ping localhost -n 3 >nul
cls
rem in here user types name he wants to be his account name
:login
title login
cls
echo Welcome to Microsoft Windows 7!
echo Before we begin, please type your name.
set /p name=here:
if "%name%"=="admin" goto admin
if not "%name%"=="admin" goto ms
rem ms=menu start
:ms
echo %time%
echo Hello %name%
echo Type HELP for list to commands
set /p command=here:
if "%command%"=="help" goto help
if "%command%"=="exit" goto exit
if "%command%"=="calendar" goto cal
goto ms
rem wc=wrong command
:admin
CLS
echo hello %name% to the admin panel
echo type HELP for list to commands
set /P command=here:
if "%command%"=="help" goto help
if "%command%"=="exit" goto exit
if "%command%"=="calendar" goto cal
GOTO :ADMIN
Okay but you don't need to start systeminfo and all that.

Batch variables do not work

I have the following batch script:
#echo off
color 2f
title "USERS MANAGEMENT IN A LAN"
:top
echo ***************************************************************
echo.
echo SELECT ACTIONS
echo.
echo ***************************************************************
echo.
echo [1] Ping the service Params: unu
echo [2] TBD
echo.
echo [e] Exit
echo.
echo ***************************************************************
echo Enter the number of the website which you would like to go to:
echo.
set /p udefine=
echo.
echo ***************************************************************
if %udefine%==1 (
echo Give the parameters:
set /p argi=
set /p argii=
START /B java -jar JavaClient.jar %argi% %argii%
)
if %udefine%==e goto exit
cls
echo ***************************************************************
echo.
echo Thank You for using it
echo.
echo ***************************************************************
echo Type [e] to exit or [b] to go back and select another option.
echo.
set /p udefine=
echo.
echo ***************************************************************
if %udefine%==b goto top
if %udefine%==e goto exit
:exit
cls
echo ***************************************************************
echo.
echo Thank You for using it
echo.
echo ***************************************************************
pause
exit
The problem is that if I run it on the first time, the java jar file is throwing exceptions because it doesn't understands the variable arguments %argi% and %argii%. I press [b] to start again at the options menu, I do the same thing again and voila, it works! Why? Why it doesn't work at the first time, and if i press [b] to go back and put again the args it works fine every time?
I start the app:
If I kill the script with Ctrl-C and reopen it, it will have the same behaviour again...first time error, and then success.
Thank you!
you need delayed expansion :
#echo off
setlocal enableDelayedExpansion
color 2f
title "USERS MANAGEMENT IN A LAN"
:top
echo ***************************************************************
echo.
echo SELECT ACTIONS
echo.
echo ***************************************************************
echo.
echo [1] Ping the service Params: unu
echo [2] TBD
echo.
echo [e] Exit
echo.
echo ***************************************************************
echo Enter the number of the website which you would like to go to:
echo.
set /p udefine=
echo.
echo ***************************************************************
if %udefine%==1 (
echo Give the parameters:
set /p argi=
set /p argii=
START /B java -jar JavaClient.jar !argi! !argii!
)
if %udefine%==e goto exit
cls
echo ***************************************************************
echo.
echo Thank You for using it
echo.
echo ***************************************************************
echo Type [e] to exit or [b] to go back and select another option.
echo.
set /p udefine=
echo.
echo ***************************************************************
if %udefine%==b goto top
if %udefine%==e goto exit
:exit
cls
echo ***************************************************************
echo.
echo Thank You for using it
echo.
echo ***************************************************************
pause
exit

incorrect syntax command in batch file

i'm new to the coding of batch files and got an error wich i can not solve..
the problem occurs at the :secName , I made a printscreen at the flash(just before it exits cmd), and it said: "so your name is [what %name% is]"and then "the syntax of the command is incorrect.
goto was unexpected at this time."
i've got this coding done now:
#echo off
goto Welcome
title The Game Of Everything
:welcome
echo.
echo Welcome!
echo What is your name?
set /p name=Enter:
goto secName
:secName
cls
echo.
echo so your name is %name%?
set /p secName:yes or no?:
if %secName%== yes goto begin
if %secName%==no goto welcome
:begin
cls
echo.
echo Welcome %name%, to "The Game Of Everything"!
echo I hope you enjoy this mini-game, downloadable on your computer!
echo.
echo It isn't the prettiest, but who gives a toss right?
echo press any key to continue...
pause>nul
exit
change this:
set /p secName:yes or no?:
to this
set /p secName=yes or no?:

Batch opening wrong file type

So here's my ENTIRE code:
#echo off
cls
color fc
:Start
cls
echo Welcome to -{GAMELOADER}-
set/p u=Username:
if %u%==username goto Correct1
if not %u%==username goto Incorrect
:Incorrect
cls
echo You Have Entered Incorrect Pass And/Or Username!
set/p t=Try Again? (Y/N)
if %t%==Y goto Start
if %t%==y goto Start
if %t%==N goto Quit
if %t%==n goto Quit
:Correct1
set/p p=Password:
if %p%==password goto Open
if not %p%==password goto Incorrect
:Open
cls
echo Games:
echo ------------------------
echo [1]Kerbal Space Program
echo ------------------------
set/p g=Choice:
if %g%== 1 goto KSPEnd
:KSPEnd
start "" "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP.exe"
cls
goto Quit
:Quit
cls
echo Goodbye
Timeout 1
But the code opens the .exe AND a .txt file with exactly the same name. I can't rename the files. So basically i'm asking how to open a specific file type.
Thanks
Instead of starting C:\....\KSP.exe, first go to the right directory, then start KSP:
cd "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program"
KSP.exe
Ok I've got two things for you. Firstly I'll give you you desired solution.
Treat it like an operatable program
rem To start Kerbal Space Program:
set Path=C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program;%Path%
start KSP
Thats it. Really.
Secondly:
Use the Choice command
you keep on using set /p where choice would be much better.
Just to be convenient I redid you code with everything I would do. Have fun!
Code :
#echo off
cls
color fc
title -{GAMELOADER}-
:Start
echo Welcome to -{GAMELOADER}-
set/p u=Username:
if %u%==username goto Correct1
if not %u%==username goto Incorrect
set Er=Userid
goto :Crash
:Incorrect
cls
echo You Have Entered Incorrect Pass And/Or Username!
choice /c yn /m "Try Again?"
if %errorlevel%==1 goto Start
if %errorlevel%==2 goto Quit
set Er=Loop-End_of_stream
goto :Crash
:Correct1
set/p p=Password:
if %p%==password goto Open
if not %p%==password goto Incorrect
set Er=Passid
goto :Crash
:Open
cls
echo Games:
echo ------------------------
echo [1]Kerbal Space Program
echo ------------------------
echo.
Choice /c 1 /m "Game: "
if %errorlevel%==1 goto KSPEnd
set Er=Gameid
goto :Crash
:KSPEnd
set Path=C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program;%Path%
start KSP
goto Quit
set Er=End_of_file___UNKNOWN
goto :Crash
:Quit
cls
echo Goodbye
Timeout 1
Exit
:Crash
Rem Always useful :)
Echo Program has crashed Error: %Er%
Pause
Exit
Hope that helped. Mona

Resources