Last updated: July 16, 2022
To prevent a family member or friend from accessing your data, you can protect your sensitive files with a password.
On the web, there are dozens of programs for securing access to files with a password, but which are very often complex to use and take time to configure them.
In this article, I will show you two methods that I use often, and which may be of use to some. By the end of this article, you will be able to protect a file without any software.
Protect a Windows folder with a Batch script
Step 1:
The first step is to create a .bat file. To do this, open the program " Notepad »(Notepad) is insert this piece of text and save it as locker.bat.
@ ECHO OFF
title Folder Private
if EXIST "Control Panel." {21EC2020-3AEA-1069-A2DD-08002B30309D} "goto UNLOCK
if NOT EXIST Private goto MDLOCKER
: CONFIRM
echo Do you 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 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 your password to open this folder
set / p "pass =>"
if NOT% pass% == funinformatique goto FAIL
assign -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 folder created successfully
goto End
: End
You can replace the password which is by default in the code " FunInformatique »With the password you want to put in the file.
Step 2:
Now click on your new locker.bat file. A folder named "private" will be created automatically. Place all your files to hide there.
Step 3:
Click locker.bat again. A black Windows console will open and ask you if you want to hide your folder. Write Y if yes, or N if not. Press ENTER.
Finally your file will be gone. Click on the locker.bat file if you want to unlock it. A black Windows console will open and ask for the password. Enter your password and press ENTER.
Protect a Windows folder without any software
There is another solution that allows you to protect a file and that works well on Windows XP, 7 or Windows 10.
To do this, follow the steps above:
Step 1:
Start by creating a folder named "Private"eg. Then open notepad and iInclude this piece of text:
Step 2:
Save the file created with Notepad under the name locker. Beat for example . Copy to your folder Private all the files you want to hide, and double click on the file locker. Beat to activate protection. You will get this:
Step 3:
To unlock it: right click the file Beat, then " Edit ". Replace the previous text with:
Save, and double click on the file asked.
Thank you very much, it still works Windows 11 !
Hi
In solution 1, I would like to add in the .bat file the possibility of automatically locking the directory when the PC shuts down.
I think it's possible but I can't.
Thank you for your help.
hello, the private folder is not showing
Hello LECLERCQ,
Could you tell me what exactly is the error message you are getting? Make sure you are using the correct password.
If possible take a screenshot of the error message and share it with us here.
I remain at your disposal when you have communicated the error to me.
cordialement,
Be careful, this trick does not work if, like me, you have the "show hidden folders" option activated.
Indeed, for the trick to work, you must deactivate the option “show hidden folders”. Normally, this option is disabled by default on Windows.
For me it doesn't work at all. When I open the locker.bat file the first time, it creates a "Private" folder for me (that's OK). But then if I reopen locker.bat, and I enter "Y" and then press "Enter", the "Private" folder does not move and it is fully accessible as well as its contents. There is just a file called "┬╗" which is created next to locker.bat and "Private" and which, when I open it with notepad, is completely empty. Then locker.bat is useless it just asks me if I want to lock this file but don't.
Can someone help me please?
Hello Clément, indeed the code contains an error. You just have to replace the
quotation marks " " with double quotation marks.
Now the code is fixed.
Greetings
Hello,
The problem persists...
When I want to lock the folder by typing Y, nothing happens
Hello Jeremy,
The problem is in the script: you have to replace the double quotes « by double premiums ".
Now the script is functional.
so that your files do not appear in a Windows search, just click on folder properties >>> General>>> Attributes: click on advanced… then just uncheck "allow the indexing of the contents of this file" . and There you go ! hop, magic, the files (which can also be "hidden" will no longer appear anyway in a windows search.
Yours sincerely, 😉
Make sure the location of the private folder has not changed since it was created.
I used this method to hide my folders but after a while it shows me the empty private folder!! how can i get my files back???
please
I did this manipulation but after it shows me the empty private folder!!!
how can i recover my files?
Just look at the MDP in the .bat or display the hidden files!
enough when it comes to protecting files that are not very important… 😉 thank you for the tip!
Not very effective since it is enough simply to look at the source code of the batch program (for the 1st solution) or to come to this article to know the unlocking key (for the 2nd)
That's why there are software to convert your .bat file into an .exe file
That way people won't know how to unlock your file (Only works for the 1st solution)
For the second solution, you just need to know a little about programming and you modify the source code and blablabla. But in my opinion, the first solution is the best, only if you transform your batch program into an executable (your "file.bat" into "file.exe") with the program "bat2exe" (bat to exe)
Sincerely, Elliot
but if we search for *.avi do the hidden files appear?
No, if you apply this trick, the .avi file will not appear in case of search.