我是新来的,很抱歉我的英语和错误。
我需要帮助在批处理文件中设置变量 - >不像你想象的那么容易。 ..来自我的批处理文件:
rem set shortcut for long pc name
set pc1=LongNameOfMyPcNo.1
set pc2=LongNameOfMyPcNo.2
set pc3=LongNameOfMyPcNo.3
rem now, user can type "pc1" and in compmgmt line he get long name
set /p pc=type shortcut name
rem in next line i want get compmgmt.msc /computer:\\LongNameOfMyPcNo.1
compmgmt.msc /computer:\\%pc%
但我得到的只是compmgmt.msc / computer:\ pc1
所以,我的问题是设置不起作用(或者我使用它不好),doskey,setlocal ..也没有用。
我不想使用选择和错误级别因为我在谈论600台计算机。所以我需要创建一个“小”数据库,但我想在txt(.bat)
中进行答案 0 :(得分:0)
您实际上是在试图获得变量的双重扩展。所以你有两个选择。
使用延迟扩展
@echo off
setlocal enabledelayedexpansion
rem set shortcut for long pc name
set pc1=LongNameOfMyPcNo.1
set pc2=LongNameOfMyPcNo.2
set pc3=LongNameOfMyPcNo.3
rem now, user can type "pc1" and in compmgmt line he get long name
set /p pc=type shortcut name
set pc=!%pc%!
rem in next line i want get compmgmt.msc /computer:\\LongNameOfMyPcNo.1
compmgmt.msc /computer:\\%pc%
使用CALL SET
@echo off
rem set shortcut for long pc name
set pc1=LongNameOfMyPcNo.1
set pc2=LongNameOfMyPcNo.2
set pc3=LongNameOfMyPcNo.3
rem now, user can type "pc1" and in compmgmt line he get long name
set /p pc=type shortcut name
call set pc=%%%pc%%%
rem in next line i want get compmgmt.msc /computer:\\LongNameOfMyPcNo.1
compmgmt.msc /computer:\\%pc%