Can anyone help me with this code?

(This is with notepad and saved as .bat)

I’m trying to lock a document on my windows 10 computer, and it works but you can also get access to the “hidden” folder with wrong password. Does anyone know how to make a line of code that doesn’t allow wrong password to open the “hidden” folder. Here is the code:

@ECHO OFF
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Private goto MDPrivate
:CONFIRM
echo Are you sure 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 password to Unlock Your Secure Folder
set/p "pass=>"
if NOT %pass%== wonderhowtogoto FAIL
attrib -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
:MDPrivate
md Private
echo Private created successfully
goto End
:End

There is a lot of discussion about this script here:

https://social.microsoft.com/Forums/en-US/9a0f17af-928e-4732-a3ba-90d54ed961ea/lock-folder-without-any-software?forum=softwareresources

Also some question as to if it really works or not. Biggest issue seems to be in your present version you can just open the bat file and magically have the password, so not really secure unless you delete the bat every time.

However some others appear to have offered code variants as well. You might have a look.

1 Like

a space is missing after your password and goto statement
if NOT %pass%== wonderhowtogoto FAIL replace with
if NOT %pass%== wonderhowto goto FAIL