0

在这个批处理文件中,我试图创建一个程序,用户可以在其中输入他或她想要的密码,并在他们打开或关闭批处理文件时使用它。问题是我无法获取用户密码和(在: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
4

2 回答 2

0

我不认为你可以改变位置参数%1...... %9尝试将密码保存到变量中。

于 2012-11-25T01:13:28.893 回答
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
于 2012-11-25T11:30:38.463 回答