Thursday, 13 June 2013

How to Password Protect a Folder Using a simple Batch File


This tutorial will guide you through the steps required to create a locked folder in Windows 7 – without installing any additional 3rd party software.
While the steps below will guide you in creating a hidden and password protected folder, this method is not 100% secure. It will deter the average computer user enough, but an advanced user will be able to access the contents of this folder. If you want to create a truly secure and encrypted place to store files and folders that absolutely nobody will ever be able to access, see the tutorial
  1. Create a new folder and name it whatever you would like.
  2. lock folder example
  3. Open the folder, right-click on a blank area in it, then select New -> Text Document from the pop-up menu.

  4. Open the text file you just created by double-clicking it and copy/paste in the following text:
    cls
    @ECHO OFF
    title Folder Private
    if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
    if NOT EXIST Private 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.
    goto CONFIRM
    :LOCK
    ren Private "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    echo Folder locked
    goto End
    :UNLOCK
    echo Enter password to unlock folder
    set/p "pass=>"
    if NOT %pass%== PASSWORD_GOES_HERE goto FAIL
    attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Private
    echo Folder Unlocked successfully
    goto End
    :FAIL
    echo Invalid password
    goto end
    :MDLOCKER
    md Private
    echo Private created successfully
    goto End
    :End
  5. In the above code, replace the key PASSWORD_GOES_HERE with the password you want to use to unlock the folder. For example if you want the password to be 123456, the line should look like:
    if NOT %pass%== 123456 goto FAIL
  6. Save your new file in the .bat format with the complete file name being locker.bat. To do this, make sure to change the Save as type: to All Files (*.*).
  7. Save file text file as a batch file
    click to enlarge
  8. In the folder you created back in Step #1, double click the locker.bat file and there will now be a new folder named Private where you can put anything you want.
  9. private folder and batch file
  10. Upon exiting, double click the locker.bat file again. It will prompt you to answer whether you want to lock your folder or not. Press Y and the private folder will disappear.

  11. click to enlarge
  12. In order to retrieve the Private folder, all you have to do is double click the locker.bat file and enter the password which you set in Step #4 and the folder will appear again for you to access.

  13. click to enlarge
  14. That’s it!