Batch File That Only Runs Certain Code Upon First Use
by jackrabbit898 in Circuits > Software
771 Views, 9 Favorites, 0 Comments
Batch File That Only Runs Certain Code Upon First Use
Hello. It was hard to explain in the title, but basically what this does is makes a batch file run certain code, but it only runs it the first time the file is opened. It works by creating a text file and checking for it. This can be useful to make tutorials that only open the first time a user runs the file.
Create the File
Pretty obvious. Just create a new file and make the file extension '.bat'
Now open it in an editor.
The Code
Here is the code. In this example, it will tell a tutorial the first time the file is opened, but after that it'll just go straight to the main menu. NOTE: You'll probably want to put the batch file in a folder so it can create the text file in the folder as well. Just helps keep it organized.
@echo off
if not exist first.txt goto tutorial
if exist first.txt goto mainmenu
:mainmenu
cls
echo This is the main menu. If this opened immediately when you ran this file, you've opened this file before.
pause
exit
:tutorial
echo don't delete this! >first.txt REM this line creates the file so next time
cls
echo Welcome! This is your first time running this file! Next time you run this, you won't see this menu.
pause
exit