Password protect any Windows folder with no extra software

I’m about to show you a high tech way to password protect any folder in Windows. But before I unveil the curtain, I need to be candid with two things: one is good and the other is bad.

First the bad: I don’t recommend using this method to protect sensitive documents. It is only designed to deter people who are categorically computer illiterate, mainly newbies who have a limited knowledge of Windows.  It barely takes more than a rudimentary understanding of Windows Vista, 7 or 8 to break into your folder and filch your files.  Just think of this as a fun thing to do but not actually use in real life.

Conversely, on the good side of things: this is a pretty cool hack and it works for hiding non-critical documents such as the birthday plans for your daughter or for showing off your computer competence to your clueless Grandmother.

The recommended way to protect your stuff is to use something like the Encrypting File System that ships with the pro version of Windows.

That being said, if you’re bored and just want something fun to do keep reading:

First we need to create a new folder.  I pressed Alt + h and then n and named it “Vonnie’s stuff”.

Then we’ll enter that folder and create a new text document.  We’re actually going to delete this file later so don’t worry about the file name.

Creating a new text document in Windows 8.1

After creating the new text document double click to open it up and paste in the following batch script:

cls 
@ECHO OFF 
title Folder "Dont Touchy" 
if EXIST "fixedByVonnie Lock" goto UNLOCK 
if NOT EXIST "Dont Touchy" goto MDLOCKER 
:CONFIRM 
echo Do you really want to lock this 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 That isn't even a valid choice. 
goto CONFIRM 
:LOCK 
ren "Dont Touchy" "fixedByVonnie Lock" 
attrib +h +s "fixedByVonnie Lock" 
echo Folder locked 
goto End 
:UNLOCK 
echo Enter secret password to unlock folder 
set/p "pass=>" 
if NOT %pass%== MySuperSecretPassword goto FAIL 
attrib -h -s "fixedByVonnie Lock" 
ren "fixedByVonnie Lock" "Dont Touchy" 
echo Folder successfully unlocked
goto End 
:FAIL 
echo Wrong password my friend
goto end 
:MDLOCKER 
md "Dont Touchy" 
echo "Dont Touchy" successfully created
goto End 
:End

Let me break this down a little.  It looks complicated but it’s not so bad when you take it line by line.  I don’t just want to dump so abstruse script on you without explaining how it works.  I owe you an explanation.


Under the hood

The first line with CLS tells us to clear the screen.

@ECHO OFF forces the computer not to display any of the batch commands on the screen.

title Folder “Dont Touchy” just tells the script to change the title of the command prompt window to “Dont Touchy”.  Odds are you won’t even see this because once you double click the batch screen it disappears in the same instant it appears.

The next part checks to see if a folder named fixedByVonnie Lock exists.

if EXIST “fixedByVonnie Lock” goto UNLOCK

In the beginning this folder doesn’t exist; we only create it after we engage the lock.

Code execution moves down to the next IF condition:

if NOT EXIST “Dont Touchy” goto MDLOCKER

The Dont Touchy folder gets created in the third line from the top.  So since it exists, execution jumps down to the line labeled MDLOCKER.  It’s near the very bottom of the screen.

md “Dont Touchy”
echo “Dont Touchy” successfully created
goto End
:End

md is the command to make a directory.  So we create a directory called “Dont Touchy” (sans the quotes) and then print text to the screen so the user knows the folder was created.

Then the script ends.

Not too exciting right?

But look at the code and try to figure out what happens the second time you click the script.

The first five lines aren’t really relevant since both IF conditions are false.  Thus, the second time we run this batch file we start at the line that beings with :CONFIRM

We echo some text to the screen asking if you really want to lock the folder and then we END the script if the response is a lowercase or uppercase “n”  If the response is a lowercase or uppercase “y”, we jump to the label named :LOCK

The 13 and 14th lines from the top are kind of interesting.

If the user enters anything other than “n”, “N”, “y” or “Y” we output an error and ask the confirmation question again.  We keep doing this until we get a valid response.

Line 15 starts the LOCK section.  In line 16 we rename the “Dont touchy” folder and then issue this magic command:

attrib +h +s “fixedByVonnie Lock”

Here’s where all the magic happens.

We’re telling Windows to set the attributes of our freshly renamed folder.  The +h makes the folder hidden and +s is the magic trick that tells Windows the file is a special file known as a System file.

Since System files (files essential for Windows to work) are hidden by default, the +s attribute makes the folder super invisible because even if you enabled hidden files it wouldn’t show up.  Thus, you have to explicitly show system files to see our special locked folder (hang on I’ll show you how to do that in one sec)

The last important part of the program is line 23

if NOT %pass%== MySuperSecretPassword goto FAIL

This is your password so it keep it safe and change it to something less obvious.

Saving the batch file

Alright, so now that you know how this little file works, go to File and choose Save As.  We’re going to save the script as hide.bat.

Make sure the Save as type field is set to All Files or it won’t work.

Making hide.bat

Now we can delete the original New Text Document since we saved it as hide.bat

Fun with bat files

Now double click the hide.bat batch file to run it.

More fun with bat files in Windows 8.1

You’ll notice a new “Dont touchy” folder pops into view.

Copy the stuff you want to hide in there.

fixedbyvonnie-windows-8-1-adding-file-to-dont-touchy

Now double click the batch file a second time.

This time you’ll notice that the command prompt is asking if you really want to lock “Dont Touchy”.

Press “y” and hit enter.

Folder locking trick in Windows 8.1

Poof it’s gone!

In the graphic below you can see the folder is no longer visible from either the Windows Desktop or the command prompt.

Pretty slick eh?

Disappearing locked folders

To unlock the folder just run the script a third time.

You’ll get prompted to enter the unlock password and then, after hitting enter, the folder will immediately return to the screen.

Unlocking the locked folder in Windows 8.1

So how would your adroit grandmother break the system?

To manually view your “hidden” folders, she could press Alt + v then y and finally o (that’s an “oh”) to view Folder Options.

In the View tab, she would put a dot inside Show hidden files, folders, and drives and would also uncheck Hide protected operating system files (Recommended).

Folder Options in Windows 8.1 Hide protected operating system files

Fortunately, even if your geeky grandmother got to this point, the second she tried to uncheck “Hide protected operating system files” she would see a terrifying alert admonishing her to rethink her decision:

You have chosen to display protected operating system files (files labeled Systsem and Hidden) in File Explorer.
These files are required to start and run Windows.  Deleting or editing them can make your computer inoperable.  Are you sure you want to display these files?

You have chosen to display protected operating system files

So there you have it.

Have fun hiding stuff just remember that you should not use this to protect anything of real value.  Since it’s way too easy figure this out and since better security mechanisms such as EFS ship with Windows 8 and 8.1, you should that instead.

I repeat: never use this trick to protect anything important!

Have fun!

About

Connect with Vonnie on Twitter

Posted in Windows, Windows 7, Windows 8, Windows 8.1 Tagged with: , ,