How To Lock File And Folder Using Command Prompt (CMD) In Windows 10

Introduction 

 
A key feature in the Windows family is to lock or unlock a file or folder using the Command Prompt (Cmd). We can also use this feature in Windows 10 to lock or unlock a file or folder using the Command Prompt (Cmd), this is a very useful feature to safeguard our documents from fraudsters. 
 
If we have many more important secret documents in our laptop or PC and by chance we have to share our laptop or PC with another person and we do not want to share our documents with him/her then we can lock our documents by using Command Prompt (Cmd) without using any third-party software.
 
This tutorial will show you various ways on how to lock or unlock any file and folder using Command Prompt (Cmd) in Windows 10.
 

Lock the File Using Cmd

 
Step 1
 
From the Start menu, open the Run dialog box or you can Press the "Window + R" key to open the RUN window.
 
Step 2
 
Type "cmd" and click on the OK button.
 
Step 3
 
To lock a file, type the command given below into the command prompt and press Enter Key.  
 
cacls <File Path> /P everyone:n
 
For example: To lock the "noida_chapter.txt" file, run the command as, cacls E:\new\c#corner\noida_chapter.txt /P everyone:n, where n represents the user's access right to none.
 
lock any file
 
Note: After Locking the file using cmd, when you just want to open the file it shows the warning message as below.
 
warning message
 

Unlock the File Using Cmd

 
To unlock a file, type the command given below into the command prompt and press the Enter Key.
 
cacls <File Path> /P everyone:f
 
For example: To unlock the "noida_chapter.txt" file, run the command as, cacls E:\new\c#corner\noida_chapter.txt /P everyone:f, where f represents the user's access right to full control.
 
unlock using cmd
 

Lock the Folder Using Cmd

 
Step 1
 
From the Start menu, open the Run dialog box or you can Press the "Window + R" key to open the RUN window.
 
Step 2
 
Type "cmd" and click on the OK button.
 
Step 3
 
To lock a folder, type the command given below into the command prompt and press Enter Key.
 
cacls <Folder Path> /P everyone:n
 
For example: To lock the "c#corner" folder, run the command as, cacls E:\new\c#corner /P everyone:n, where n represents the user's access right to none
 
lock a folder using cmd
 
Note: After Locking the folder using cmd, when you just want to open the folder it shows the warning message as below.
 
warning message
 

Unlock the Folder Using Cmd 

 
To unlock a folder, type the command given below into the command prompt and press Enter Key.
 
cacls <Folder Path> /P everyone:f
 
For example: To unlock the "c#corner" folder, run the command as, cacls E:\new\c#corner /P everyone:f, where f represents the user's access right to full control.
 
unlock using cmd
 

Conclusion

 
By following any of the above methods, you can lock or unlock any file and folder using Command Prompt (Cmd) in Windows 10.
 
I hope you enjoyed this article. Follow C# Corner to learn more new and amazing things about Windows 10.
 
Thanks for reading this article.