How To: Create A Batch File To Lock A Folder In Windows Vista
Many peoples ask me for an effective way to lock folders in Windows Vista without the use of any third party software’s.You can easily create a folder in Windows Vista that will not just be invisible, but also require a password to reveal it and open it.Simply says you can easily lock a folder using Notepad.
- Open Notepad editor from Windows Vista start menu and copy the code given below.
cls
@ECHO OFF
title Folder Locker
if EXIST “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u 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 Locker “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%==type your password here goto FAIL
attrib -h -s “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}”
ren “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” Locker
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Locker
echo Locker created successfully
goto End
:End
- After copy the code to the Notepad editor,go to the code you will find “type your password here“(line 23) and change to any password you want.
- Save file as locker.bat .
- Now double click on locker.bat and it will create a folder with Locker automatically.

- After creation of the Locker folder, place the contents u want to lock inside the Locker Folder and run locker.bat again .
- It will ask for confirmation and press Y and enter key ,then Locker folder will be disappeared.
- Again click locker.bat and give your password, you will get your folder opened.
Note:
- The batch file just you created(Locker.bat) acts like a key to open the locked folder.Do not keep the batch file in the same location of the folder, since other people can open the batch file and view your password.So keep the batch file in a separate and safe place like flash memory drive.
- This trick also works for Windows XP.
Update:
You can also use this code for creating locker.bat.
@ECHO OFF
title LOCK A FOLDER
:MENU
echo **LOCK A FOLDER MENU**
echo L – Lock a folder
echo U – Unlock a folder
echo H – Unhide a hidden folder (Make sure you know the folder name)
echo A – About this program
echo X – Exit
echo Enter your choice:
set/p “chois=>”
if %chois%==L goto BEGINLOCK
if %chois%==l goto BEGINLOCK
if %chois%==U goto UNLOCKF
if %chois%==u goto UNLOCKF
if %chois%==H goto BEGINUNHIDE
if %chois%==h goto BEGINUNHIDE
if %chois%==A goto ABOUT
if %chois%==a goto ABOUT
if %chois%==X goto END
if %chois%==x goto END
:UNLOCKF
cls
echo Please enter the folder you want to UNLOCK:
set/p “lockfldr=>”
:UNLOCKF2
if EXIST %lockfldr%”.{ECF03A32-103D-11d2-854D-006008059367}” goto UNLOCK
if NOT EXIST %lockfldr%”.{ECF03A32-103D-11d2-854D-006008059367}” goto UNLOCKNOTFOUND
:BEGINLOCK
cls
echo Please enter the folder you want to LOCK:
set/p “fldr=>”
if EXIST %fldr% goto LOCK
if NOT EXIST %fldr% goto LOCKNOTFOUND
:BEGINUNHIDE
cls
echo Please enter the folder you want to UNHIDE:
set/p “lockfldr=>”
if EXIST %lockfldr%”.{ECF03A32-103D-11d2-854D-006008059367}” goto UNHIDE
if NOT EXIST %lockfldr% goto END
:LOCK
ren %fldr% %fldr%”.{ECF03A32-103D-11d2-854D-006008059367}”
goto DONELOCK
:UNLOCK
ren %lockfldr%”.{ECF03A32-103D-11d2-854D-006008059367}” %lockfldr%
goto DONEUNLOCK
ONELOCK
echo %fldr% has been successfully locked!
echo Would you like to hide this folder?[y/n] :
set/p “chide=>”
if %chide%==Y goto HIDE
if %chide%==y goto HIDE
if %chide%==N goto DONELOCK2
if %chide%==n goto DONELOCK2
ONELOCK2
echo Would you like to lock another folder?[y/n] :
set/p “dlock=>”
if %dlock%==Y goto BEGINLOCK
if %dlock%==y goto BEGINLOCK
if %dlock%==N goto MENU
if %dlock%==n goto MENU
ONEUNLOCK
echo %lockfldr% has been successfully unlocked!
echo Would you like to unlock another folder?[y/n] :
set/p “dlock=>”
if %dlock%==Y goto UNLOCKF
if %dlock%==y goto UNLOCKF
if %dlock%==N goto MENU
if %dlock%==n goto MENU
:UNLOCKNOTFOUND
echo %lockfldr% Folder not found!
echo Would you like to try again?[y/n] :
set/p “unotf=>”
if %unotf%==Y goto UNLOCKF
if %unotf%==y goto UNLOCKF
if %unotf%==N goto MENU
if %unotf%==n goto MENU
:LOCKNOTFOUND
echo %fldr% Folder not found!
echo Would you like to try again?[y/n] :
set/p “notf=>”
if %notf%==Y goto BEGINLOCK
if %notf%==y goto BEGINLOCK
if %notf%==N goto MENU
if %notf%==n goto MENU
:AFTERUNHIDE
echo Would you like to UNLOCK this folder?[y/n] :
set/p “afthide=>”
if %afthide%==Y goto UNLOCKF2
if %afthide%==y goto UNLOCKF2
if %afthide%==N goto MENU
if %afthide%==n goto MENU
:HIDE
attrib +h +s %fldr%”.{ECF03A32-103D-11d2-854D-006008059367}”
echo %fldr% is now hidden! Please take note of the folder name because you will need it to unhide the folder.
goto DONELOCK2
:UNHIDE
attrib -h -s %lockfldr%”.{ECF03A32-103D-11d2-854D-006008059367}”
echo %lockfldr% is now visible!
goto AFTERUNHIDE
:ABOUT
echo +—————–+
echo ¦ LOCK A FOLDER ¦
echo +—————–+
goto MENU
:END
The features of this script are:
- Menu
- Lock a Folder / Lock a Folder and hide it.
- Unlock a Folder/ Unlock a folder and unhide it.
- You can lock/unlock a folder of your choice. Just type in the folder name.
- You can unhide a hidden folder of your choice, but you need to know the name of the folder you are going to unhide.
Popularity: 6%
Did You Like This Post? Then You Might Find These Also Interesting:
Written by Tony on March 22nd, 2009 with
2 comments.
Read more articles on Windows Tricks.






#1. October 15th, 2009, at 6:49 PM.
I’m not sure if I am following this correctly. With the first segment of code, the locker folder is created after running locker.bat. Then after placing contents inside and running I chose Y to lock the folder and a file named o(with an accent) was created and it contained 0 bytes. The locker folder remained completely open. With the second segment of code I ran the .bat and choose lock a folder. At this point the same o(accent) 0 byte file was created and the folder locker was not created. I would love to learn how to work all this out, if this could be possible. I am running Vista and don’t understand much about batch files just yet. Thanks for the starters though.