我写了可以检查用户input的基本脚本。 如果用户未填写脚本,则必须再次询问名称input。 但是出了点问题,我错过了?
@echo OFF title Enter your name color 0a set /p Name="Your name: " %=% :start if "%Name%"=="" (goto try) :try cls color 0a echo You must enter your name! color 0c set /p Name="Your name: " %=% if "%Name%"!="" (goto init) else (goto try) :init color 0a cls Echo %Name% is saved... reg add "HKEY_CURRENT_USER\Software\example" /v "YourName" /t REG_SZ /d "%Name%" /f Pause&Exit
if "%Name%"!="" ...
不是一个有效的语法。 而是使用:
if not "%Name%"=="" ...
要么
if "%Name%" neq "" ...
我改变了代码,现在它的工作原理!
@echo OFF title Name pl0x color 0a :start set /p Name="Your name: " %=% if "%Name%"=="" ( cls color 0a echo You must enter your name! color 0c goto :start ) else ( color 0a cls Echo %Name% saved... reg add "HKEY_CURRENT_USER\example" /v "YourName" /t REG_SZ /d "%Name%" /f Pause&Exit )