How to password protect folders in Windows without third-party software [Guide]

There are a variety of third-party software packages with which you can add password to folders in Windows. However, you can also add a password to a folder without any additional software. You can instead set up a batch file that adds a password to the folder, allowing you to password protect folders without requiring third-party software in Windows XP, Vista, 7, 8, and 8.1. Read on to learn more.

Firstly, you should create a new folder that will include your password protected subfolder. Once you have set up a new folder, navigate to it in Windows Explorer, open it and right-click the area within Windows Explorer where the folder files are listed. Click New > Text document to add a new txt document to the folder as below.

batch file4

Then open the text document, and copy (Ctrl + C) and paste (Ctrl + V) the following code into it:



title Folder Private

if EXIST "HTG Locker" goto UNLOCK

if NOT EXIST Private goto MDLOCKER


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.



ren Private "HTG Locker"

attrib +h +s "HTG Locker"

echo Folder locked

goto End


echo Enter password to unlock folder

set/p "pass=>"


attrib -h -s "HTG Locker"

ren "HTG Locker" Private

echo Folder Unlocked successfully

goto End


echo Invalid password

goto end


md Private

echo Private created successfully

goto End


Note the PASSWORD_GOES_HERE text which you should change to a suitable password. Save the document as locker.bat (you will need to select “All Files” in Notepad’s saving window inorder to save the file as .bat file instead of .txt) and close Notepad. That saves the document as a batch file, and you can delete the original text file.

batch file3

When you double-click the batch file to run it for the first time, it creates a folder titled Private. There you should move a variety of documents to the folder which you will now lock. Click on the batch file again, and press y and the Return to lock the folder.

batch file

The Private folder disappears, and to make it visible again you should click the batch file. That asks you for a password, and you should enter the same password that you entered in the script. If the password matches the one you put in the script, the Private folder reappears. Now you can open it again, add more files and click the batch file to lock it.

batch file2

With this script you can add passwords to a variety of folders in Windows without any third-party software. Certainly, the script is not entirely secure; but the batch file also makes the folder disappear as well as add a password. For more full-proof passwords third-party software might be a better alternative.

Related Posts

  • Ayan Mallick

    1. its not working full user unchecked system file in folder option.
    2. which language is this? is this “C” ?

  • Ayan Mallick

    If somehow or accidentally the bat file deleted or missing, then how we access the private folder or that data which in the private folder.

    please tall some way !!!!

  • Kalle

    if open .bat file with Free File Viewer you can see password there.

  • Bob

    Interesting idea.

    As other comment, unhide and it’s there.

    Biggest issue is for a password protected folder – the password’s in the bat file in plain text…

  • David Roper

    Excellent article again, Matthew. I would add a layer of “No Touch” by compiling the batch file to an exe to prevent nosey wanna be programmers changing the logic inside. Freeware compilers do exist.


    what does “HTG” mean as in “HTG Locker” the name the folder is given? This only hides the folder if you have “do not show hidden files and folders” enabled in “Folder Options”. I guess you know you can simply put quotation marks around the ‘file name’ and any extension in notepad and it will save it as that, “locker.bat”, “jimmy.reg”, “blind_as_a.bat”