Folder locking is a method that is used to protect the contents of a specific folder by restricting unauthorized access. The process typically involves security measures such as passwords or encryption to prevent unwanted users from viewing, modifying, or deleting the data or files within the locked folder. Folder locking is beneficial in various scenarios, such as maintaining the privacy of sensitive documents, securing personal information, or safeguarding important files. There are multiple ways to lock a folder; we will learn the following method to understand How to lock a folder in Windows 11:
- Using Batch Script
Batch script to folder lock for windows 11
Step-by-step implementation
Step 1- Batch script to lock a folder
In this step, we will be writing a batch script that, on running, will create a folder, and once we add data or files that need to be protected, we will again run that script, which eventually asks to lock the folder. Afterward, that folder will not be visible even in hide or unhide mode. To access that folder, we need to run a batch script and enter the password. If the correct password is entered, that folder will come into view; otherwise, noting will be shown.
@ECHO OFF
cls
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 you want to lock the folder (Y/N)
set /p "cho=>"
if /i "%cho%"=="Y" goto LOCK
if /i "%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=>"
REM Check the entered password (replace "paulsofts@123" with the actual password)
if /i NOT "%pass%"=="paulsofts@123" 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
Let us understand the above script in detail. The script is performing the following actions:
- Checks if a folder named “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” exists.
- If the folder exists, it goes to the UNLOCK section.
- If the folder doesn’t exist and there’s no “Locker” folder, it goes to the MDLOCKER section to create a new folder.
- If the user confirms to lock the folder, it renames the “Locker” folder to “Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}” and hides it.
- If the user confirms to unlock the folder, it prompts for a password. If the correct password is entered, it unhides the folder and renames it back to “Locker.”
- If the password is incorrect, it displays an error message.
- If neither locking nor unlocking conditions are met, it goes to the
End
label.
Note: Make sure to replace the password from paulsofts@123 with the actual password.
Step 2- Save as batch file
After we have the script in our text editors, such as Notepad, We need to save it and make sure we save it as .bat file extension.
Step 3- Testing
Run batch script:
After running the lock.bat file we created in the previous step, it will generate a locker folder.
Output: