How to Lock a Folder Using a Batch File

Download ArticleDownload 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 How.com.vn teaches you how to create a locker folder using a batch file.


  1. How.com.vn English: Step 1 Open Notepad.
    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. How.com.vn English: Step 2 Copy the following batch script.
    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 OFFtitle Folder Lockerif EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCKif NOT EXIST Locker goto MDLOCKER:CONFIRMecho Are you sure you want to Lock the folder (Y/N)set/p "cho=>"if %cho%==Y goto LOCKif %cho%==y goto LOCKif %cho%==n goto ENDif %cho%==N goto ENDecho Invalid choice.timeout 1goto CONFIRM:LOCKren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"echo Folder lockedtimeout 3goto End:UNLOCK@echo offset "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=%%pif NOT %password%==TYPE_YOUR_PASSWORD_HERE goto FAILattrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Lockerecho Folder Unlocked Successfullytimeout 1goto End:FAILecho Invalid Passwordtimeout 1goto end:MDLOCKERmd Lockerecho Locker created successfullytimeout 5goto End:End
    Advertisement
  3. How.com.vn English: Step 3 Paste the code into Notepad.
    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. How.com.vn English: Step 4 Change the password.
    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. How.com.vn English: Step 5 Save the document as a batch file.
    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. How.com.vn English: Step 6 Close the window.
    Once you are finished saving the Batch file, you can close Notepad.
  7. How.com.vn English: Step 7 Run the batch file by double-clicking it.
    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. How.com.vn English: Step 8 Move all the things you want to hide into the Locker folder.
    You can move objects into the folder by dragging and dropping them, or you can copy and paste them into the folder.
  9. How.com.vn English: Step 9 Double-click on the locker.bat file again.
    A Command Prompt will open. It will ask you if you want to lock the folder.
  10. How.com.vn English: Step 10 Press Y and then press ↵ Enter.
    The Locker folder will disappear from the folder. This indicates it is locked.
  11. How.com.vn English: Step 11 Unlock the folder.
    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?
    How.com.vn English: 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?
    How.com.vn English: 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?
    How.com.vn English: 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
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      Advertisement

      About This Article

      How.com.vn English: Travis Boylls
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for How.com.vn. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College. This article has been viewed 329,468 times.
      How helpful is this?
      Co-authors: 41
      Updated: February 5, 2023
      Views: 329,468
      Categories: Hacks
      Thanks to all authors for creating a page that has been read 329,468 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement