Batch File That Only Runs Certain Code Upon First Use

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

About: 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.

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: 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

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

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    2 Discussions

    0
    muntadhar
    muntadhar

    4 years ago

    how to make extension .bat ?

    0
    jackrabbit898
    jackrabbit898

    Reply 4 years ago

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