PDF download Download Article
A quick & easy guide to securing your files
PDF download Download Article

Do you have items you want to keep hidden on your computer? Creating a locked folder using a batch script is a fun and easy way to hide files in low-stakes situations that don't require files to be encrypted. This wikiHow teaches you how to create a locker folder using a batch file.

Locking a File with Batch File

Open Notepad and paste the batch script into a blank document. Then, change "TYPE_YOUR_PASSWORD_HERE" in the script to your password. Save the file as a batch file and run the file. Then, move the folders and files you want to lock inside the file.

  1. Notepad has an icon that resembles a blue notebook folder. Use the following steps to open Notepad:
    • Click the Windows Start Menu.
    • Type "Notepad."
    • Click Notepad.
  2. The batch script is in the box below. Highlight the entire script. Right-click it and click Copy, or press "Ctrl + C." The script is as follows:[1]
      cls
    
    @ECHO OFF
    
    title Folder Locker
    
    if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
    
    if NOT EXIST Locker goto MDLOCKER
    
    :CONFIRM
    
    echo Are you sure you want to Lock the folder (Y/N)
    
    set/p "cho=>"
    
    if %cho%==Y goto LOCK
    
    if %cho%==y goto LOCK
    
    if %cho%==n goto END
    
    if %cho%==N goto END
    
    echo Invalid choice.
    
    timeout 1
    
    goto CONFIRM
    
    :LOCK
    
    ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    echo Folder locked
    
    timeout 3
    
    goto End
    
    :UNLOCK
    
    @echo off
    set "psCommand=powershell -Command "$pword = read-host 'Enter Password to Unlock folder' -AsSecureString ; ^
        $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
            [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
    
    if NOT %password%==TYPE_YOUR_PASSWORD_HERE goto FAIL
    
    attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
    
    echo Folder Unlocked Successfully
    
    timeout 1
    
    goto End
    
    :FAIL
    
    echo Invalid Password
    
    timeout 1
    
    goto end
    
    :MDLOCKER
    
    md Locker
    
    echo Locker created successfully
    
    timeout 5
    
    goto End
    
    :End
    
    Advertisement
  3. Go back to your blank Notepad document. Right-click at the top of the page and click Paste, or press "Ctrl + V" to paste the code into Notepad.
  4. Locate where it says "TYPE_YOUR_PASSWORD_HERE" in the script. It's about three-quarters of the way down. It's in the line that starts with "if NOT %password%==".
  5. Use the following steps to save the Notepad document as a batch file:
    • Click File.
    • Click Save as.
    • Click the drop-down menu next to "Save as type."
    • Select All files (*.*).
    • Type a file name in the File Name field (i.e. LockedFolder).
    • Type ".bat" at the end of the file name (I.e. LockedFolder.bat).
    • Click Save.
  6. Once you are finished saving the Batch file, you can close Notepad.
  7. Navigate to where you saved the batch file in File Explorer. Double-click the batch file to run it. This will create a new folder called "Locker" in the same folder as the batch file.
  8. You can move objects into the folder by dragging and dropping them, or you can copy and paste them into the folder.
  9. A Command Prompt will open. It will ask you if you want to lock the folder.
  10. The Locker folder will disappear from the folder. This indicates it is locked.
  11. When you want to gain access to the folder again, use the following steps to make the Locker folder reappear:
    • Double-click the batch file to run it.
    • Enter the password you input into the batch file before you saved it.
    • Press the Enter key.
  12. Advertisement


Community Q&A

Search
Add New Question
  • Question
    How do I re-lock the file?
    Community Answer
    Community Answer
    Double-click the file again. It will ask for a password. Enter the password, and you're done!
  • Question
    How do I reset the password?
    Community Answer
    Community Answer
    Right-click on the .bat file. After doing so, click 'edit.' You can change the code through this.
  • Question
    My folder will not re-lock when typing Y. What do I do?
    Community Answer
    Community Answer
    Are you sure you're typing everything correctly? What Windows version are you using?
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Video

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

Warnings

Advertisement

You Might Also Like

Add a Password to a .Bat FileA Complete Guide to Adding Password Protection to .Bat Files
Protect Folders With Passwords3 Easy Ways to Protect a Folder With a Password
Lock a Folder on Windows Lock a Folder on Windows: A Step-by-Step Guide
Encrypt FilesEncrypt Files
Password Protect Files on a Mac4 Easy Ways to Password Protect Files on Mac
Make a Zip File6 Simple Ways to Create a .ZIP File from Files or Folders
Hide Files in Cmd Hide Files in Windows Using CMD
Write a Batch FileWrite a Batch File
Delete a File in Microsoft Windows Using Batch FilesDelete a File in Microsoft Windows Using Batch Files
Send Documents Securely on PC or MacSend Documents Securely on PC or Mac
Make a Computer DiaryMake a Computer Diary
Hide a File in an Image FileHide a File in an Image File
Make an Invisible File Make Hidden Folders and Files on Your Computer
Add a Password to a RAR FileAdd a Password to a RAR File
Advertisement

About This Article

Travis Boylls
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Travis Boylls. Travis has been a tech writer at wikiHow for more than 10 years. He has also worked in technical support for Dish Network and AT&T Wireless. He studied graphic design and web design at Pikes Peak Community College. He specializes in Windows, macOS, Linux, Android, iOS, and video game consoles. Travis has had a fascination with computers and technology that goes all the way back to childhood. He is proficient in all manner of software and computer operating systems. This article has been viewed 344,894 times.
How helpful is this?
Co-authors: 41
Updated: September 23, 2025
Views: 344,894
Categories: Hacks
Thanks to all authors for creating a page that has been read 344,894 times.

Is this article up to date?

Advertisement