Windows 7定义了bat文件和msg命令的变量

时间:2011-02-20 14:38:05

标签: windows-7 batch-file messaging

我有一个类似的.bat文件:

msg userA System will be restarted
msg userB System will be restarted
msg userC System will be restarted
msg userD System will be restarted
msg userE System will be restarted
msg userF System will be restarted
msg userG System will be restarted

我可以为消息部分定义变量,如:

message = System will be restarted 
msg userA message
msg userB message
msg userC message
msg userD message
msg userE message
msg userF message

还可以将用户定义为数组吗?如:

users= [userA, userB, userC, userD, userE, userF]
message = System will be restarted 
msg users message

感谢您的建议。

编辑:我将这些行写入了bat文件:

set MESSAGE = System will be restarted
msg userA %MESSAGE%

当我点击bat文件时,我得到了截图:screenshot

1 个答案:

答案 0 :(得分:3)

  1. 是;你可以使用environment variables

    set MESSAGE=System will be restarted 
    msg userE %MESSAGE%
    
  2. Yes

    set USERS=(userA userB userC userD userE userF)
    set MESSAGE=System will be restarted 
    
    for %%i in %USERS% do msg %%i %MESSAGE%