Introduction: Batch File That Only Runs Certain Code Upon First Use

Picture of 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.

Step 1: Create the File

Picture of Create the File

Pretty obvious. Just create a new file and make the file extension '.bat'

Now open it in an editor.

Step 2: The Code

Picture of 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



echo This is the main menu. If this opened immediately when you ran this file, you've opened this file before.




echo don't delete this! >first.txt REM this line creates the file so next time


echo Welcome! This is your first time running this file! Next time you run this, you won't see this menu.




muntadhar (author)2016-04-18

how to make extension .bat ?

jackrabbit898 (author)muntadhar2016-04-18

where it says .txt double click that and make it bat instead of txt

About This Instructable




Bio: I am a programmer, and I can program in Python, HTML, batch, Visual Basic, XML (Although that's not really a programming language), and VBScript.
More by jackrabbit898:Batch file that only runs certain code upon first useROBLOX hacking tool prank
Add instructable to: