在这个批处理文件中我试图创建一个程序,用户可以输入他或她想要的密码,并在打开或关闭批处理文件时使用它。
问题是我无法获得用户密码和(在:MDLOCKER和:UNLOCK)和脚本的解锁部分工作。当它最终运行时,它接受任何密码
如果你能提供帮助,那将非常感谢。
enter code here@ECHO OFF
prompt Filelocker`enter code here`
:START
echo what do you want to do? (insert number)
echo 1 Lock current folder
echo 2 Unlock current folder
echo 3 Make new locked folder
set/p "cho=>"
if %cho%==1 goto CONFIRM
if %cho%==2 goto UNLOCK
if %cho%==3 goto NEW
echo not valid
goto start
: NEW
title Folder Locked files
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto ALREADY
if NOT EXIST Locker goto MDLOCKER
:ALREADY
echo folder already exist!
echo try unlocking if folder can not be found
pause
goto START
: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
:MDLOCKER
md Locker
echo Locked folder created....
echo folder is now created
echo enter password for your file.
set/p 1%=
echo password accepted
goto start
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==%1% 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
echo 2 MORE TRYS LEFT
pause
goto
:End
答案 0 :(得分:0)
我认为您无法更改位置参数%1
.. %9
。请尝试将密码保存到变量中。
答案 1 :(得分:0)
问题在于:
set/p 1%=
你为什么这样做?
您不能使用像var-name这样的特殊var。 而且你不能在var-name的开头使用数字。
您可以使用命令Choice而不是您正在使用的所有IF语句:
@ECHO OFF
prompt Filelocker`enter code here`
:START
echo what do you want to do? (insert number)
echo 1 Lock current folder
echo 2 Unlock current folder
echo 3 Make new locked folder
choice /C 123 /M "choose an option: "
IF %ERRORLEVEL% EQU 1 (goto :CONFIRM)
IF %ERRORLEVEL% EQU 2 (goto :UNLOCK)
IF %ERRORLEVEL% EQU 3 (goto :NEW)
:NEW
title Folder Locked files
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" (
echo folder already exist!
echo try unlocking if folder can not be found
pause
goto :START
)
if NOT EXIST "Locker" (goto :MDLOCKER)
:CONFIRM
choice /C YN /M "Are you sure u want to Lock the folder? "
IF %ERRORLEVEL% EQU 1 (goto :LOCK)
IF %ERRORLEVEL% EQU 2 (goto :END)
: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
:MDLOCKER
md "Locker"
echo Locked folder created....
echo folder is now created
echo enter password for your file.
set/p "VAR=>> "
echo password accepted
goto :start
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>> "
if NOT "%pass%"=="%VAR%" 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
echo 2 MORE TRYS LEFT
pause
goto :UNLOCK
:End