再将程序修改了一下,但又有了两个从没想到过的难题:
1.当用SET设置超过9个变量时怎么办?
2.当出现变量空间溢出时怎么办?
现在将程序分作了两个程序,一个主程序 CC.BAT, 一个密码子程序 password.bat,现在可以做到不允许用 Ctrl+C 来非法终止密码验证过程了!
密码子程序 password.bat
@echo off
rem 好像变量只能用9个,本程序中变量用到了10个,结果发现最后一个变量geiding2无法赋值而运行出错!使用了shift命令还是没用,如何解决?
shift
rem ------程序给定的初始密码 123456-------------
rem 密码可为任意位长度的数字,用户可更改。nul
if "%verify%"=="pass" goto end
goto start
:end
if exist pass.bat del pass.bat>nul
echo.
echo Run my BAT or enter windows ...
密码子程序 password.bat
@echo off
rem 可自定义密码的处理程序 password.bat
rem ------程序给定的初始密码 123456-------------
set geiding=123456
rem --------调用用户已设定的密码---------------
if exist c:\windows\msapps\keyfile.bat call c:\windows\msapps\keyfile.bat>nul
rem -----初始化设置-------
echo set verify=>pass.bat
set inputecho=Please input the password>nul
set option=quit>nul
set startinfo=press C>nul
goto input
:change
set passecho=
set password=
set inputecho=Input the OLD password>nul
set option=setkey1>nul
set startinfo=...>nul
rem --------密码验证---------------------------
:input
cls
echo Change password %startinfo%
for %%a in (1 2) do echo.
rem 将提示信息另显出来不要加在CHOICE循环后面,否则在DOS下运行时回闪很利害。
echo %inputecho% (clear-X OK-Y): %passecho%
choice /c:1234567890XYC /n
if errorlevel 13 goto change
if errorlevel 12 goto inputok
if errorlevel 11 goto clear
set passecho=%passecho%*
if errorlevel 10 set password=%password%0
rem 如果取值为0,则必须在下面的for循环前加上if not errorlevel 10,否则会出错!后同。
if not errorlevel 10 for %%n in (1 2 3 4 5 6 7 8 9) do if errorlevel %%n set password=%password%%%n
goto input
:inputok
cls
echo Change password %startinfo%
for %%a in (1 2) do echo.
echo %inputecho% (clear-X OK-Y): %passecho%
if == goto %option%
:error
for %%a in (1 2) do echo.
echo password error!!!
echo.
pause
:clear
set passecho=
set password=
goto input
rem --------密码修改---------------------------
:setkey1
set geiding1=
set setecho1=
:setting1
cls
echo setting password ...
for %%a in (1 2) do echo.
echo Input the OLD password (clear-X OK-Y): %passecho%
for %%a in (1 2) do echo.
echo Input the NEW password (clear-X OK-Y): %setecho1%
choice /c:1234567890XY /n
if errorlevel 12 goto setkey2
if errorlevel 11 goto setkey1
set setecho1=%setecho1%*
if errorlevel 10 set geiding1=%geiding1%0
if not errorlevel 10 for %%n in (1 2 3 4 5 6 7 8 9) do if errorlevel %%n set geiding1=%geiding1%%%n
goto setting1
:setkey2
rem 密码不能设为空,否则下次无法进入了。下同。
if "%geiding1%"=="" goto setting1
set geiding2=
set setecho2=
:setting2
cls
echo setting password ...
for %%a in (1 2) do echo.
echo Input the OLD password (clear-X OK-Y): %passecho%
for %%a in (1 2) do echo.
echo Input the NEW password (clear-X OK-Y): %setecho1%
for %%a in (1 2) do echo.
echo Again the NEW password (clear-X OK-Y): %setecho2%
choice /c:1234567890XY /n
if errorlevel 12 goto setok
if errorlevel 11 goto setkey2
set setecho2=%setecho2%*
if errorlevel 10 set geiding2=%geiding2%0
if not errorlevel 10 for %%m in (1 2 3 4 5 6 7 8 9) do if errorlevel %%m set geiding2=%geiding2%%%m
goto setting2
:setok
if "%geiding2%"=="" goto setting2
if "%geiding1%"=="%geiding2%" goto write
for %%a in (1 2) do echo.
rem 说两次设定的密码不一致怎么表达?我英语实在...
echo First and second out of line with the password !
echo.
pause
goto setkey1
:write
set geiding=%geiding2%
if not exist c:\windows\nul md c:\windows
if not exist c:\windows\msapps\nul md c:\windows\msapps
echo set geiding=%geiding%>c:\windows\msapps\keyfile.bat
:quit
echo set verify=pass>pass.bat
rem 还有一个问题,为什么为里直接用set verify=pass,返回到主程序后赋值不成功?非得要转借另一个子程序?
cls