:start
net view
set nick=
echo.
echo.
echo If you want to select a common target, enter one of the following:
echo (computer1)
echo (computer2)
echo (computer3)
set /P target="Enter one of the above computer names (without \\):
IF "%target%"=="(computer1)" do(
set nick=(computer1)
goto shortcut
)
IF "%target%"=="(computer2)" do(
set nick=(computer2)
goto shortcut
)
IF "%target%"=="(computer3)" do(
set nick=(computer3)
goto shortcut
)
ELSE goto shutdown
上面的代码是一个程序,应该允许您键入一个快捷方式来存储变量昵称中的计算机名称。如果批处理中的字符串中的语句不返回true?
我很新的批,FYI。
当我运行该程序时,无论如何执行第一个if语句(即使%target%是不同的值)。我该如何解决这个问题?我已经完成了比较字符串的深入研究,但都没有成功。
P.S.我需要在关机页面中使用nick,所以我真的需要根据用户输入的内容设置值。此外,(电脑)不属于该计划的一部分;他们是我为了隐私而替换的实际计算机名称。
谢谢!
通过句子“第一条if语句不管执行什么”,你的意思是说你的代码执行后变量'nick'变成'(computer1)'吗? – 2014-11-07 01:14:13
@ Fumu7是的,无论用户输入什么值,变量昵称都被设置为(computer1)。 – ajc2000 2014-11-07 01:15:47
我的坏!忘记更改if语句中的字符串。现在可能更容易理解@ Fumu7 – ajc2000 2014-11-07 01:19:48