How to Add a Password to a .Bat File

Adding a password protection to a windows .batch script isn't incredibly difficult, but it would be hard to accomplish without any instructions. If you're willing to take the time to learn then you'll have some password protection in no...

Method 1 of 2:

Writing Your Code

  1. Picture 1 of How to Add a Password to a .Bat File
    Open Notepad. You can open the Notepad application by going to Start, then All Programs, and then Accessories. In Accessories you'll find Notepad. Windows users can just type "notepad", without quotes, into the start menu and hit enter. The application will open. [1]
  2. Picture 2 of How to Add a Password to a .Bat File
    Begin your code with @ echo off. This is the line that you will use to start your script. Scripting is writing the code that causes the program to run correctly. This line allows you to start writing text. [2] After you write that, you will copy the code below.
      1. :A
  3. echo enter password to activate program.
  4. set/p "pass=>"
    1. if NOT %pass%== passwordhere goto :FAIL
  5. Picture 3 of How to Add a Password to a .Bat File
    Add the finishing touches to end your script. At the end of your program, you need to add the following lines:
      1. :FAIL
      1. echo Invalid password. If you want to write additional text you can. If you want to have time between the first line of text and the second line of text add a line that says 'ping localhost (number)'. This designates the amount of time between each line of text. Put it between the second and third line. If you want your program to run slowly and give people time to use each line of text, make the ping localhost time longer. The pause in between each line of text that shows up from the code would be the ping localhost time. If you want the program to say 'Hello' and then say 'how are you' five seconds later, you would write ping localhost 5
      2. goto :end
    1. :end
Method 2 of 2:

Finishing Up

  1. Picture 4 of How to Add a Password to a .Bat File
    Change "passwordhere" to the password of your choice. You can choose whatever password you want. It can be as long as you want too. Just remember to keep the quotation marks. [3]
  2. Picture 5 of How to Add a Password to a .Bat File
    Save the file with an ending of .bat. The default will be .txt, so you'll have to change this. If you've already saved the file just go to file, then save as, and then change the extension to .bat. You might need to check the box saying 'show extension' if you don't see .txt.
  3. Picture 6 of How to Add a Password to a .Bat File
    Navigate to Performance and Maintenance. You can reach this tab from the Control Panel of your computer. Now go to Scheduled Tasks and navigate to the file that you just created. You can set it to run whenever you want it to – when someone tries to log on, when they try to open a certain file or folder, or any other prompt. [4]
Update 04 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile