Database 使用SET、DOSKEY等在批处理文件中创建数据库

Database 使用SET、DOSKEY等在批处理文件中创建数据库,database,batch-file,cmd,set,Database,Batch File,Cmd,Set,我是新来的,所以很抱歉我的英语和在帖子中的错误 我需要帮助在批处理文件中设置变量->并不像你们想的那个么容易。。我的批处理文件中的示例: 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 nam

我是新来的,所以很抱歉我的英语和在帖子中的错误

我需要帮助在批处理文件中设置变量->并不像你们想的那个么容易。。我的批处理文件中的示例:

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

所以,我的问题是set不工作(或者我使用它不好)、doskey、setlocal。。也不起作用


我不想使用选择和错误级别,因为我说的是600台计算机。因此,我需要创建一个“小”数据库,但我想在txt(.bat)中创建它。

您实际上是在尝试对变量进行双重扩展。所以你有两个选择

使用延迟扩展

@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%
使用呼叫集

@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%

你实际上是在试图得到一个变量的双重展开式。所以你有两个选择

使用延迟扩展

@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%
使用呼叫集

@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%

使用
compmgmt.msc/计算机:\\!%pc%启用延迟扩展。请参阅使用
compmgmt.msc/计算机:\\\!%pc%启用延迟扩展。请参见
调用
行中缺少百分之一的符号,它应该是:
调用集pc=%%%pc%%
调用
行中缺少百分之一的符号,它应该是:
调用集pc=%%%pc%%