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

Windows 7 Windows 7为bat文件和msg命令定义变量,windows-7,batch-file,messaging,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 r

我有这样一个.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文件时,我得到了屏幕截图:

  • 对,;您可以使用:

  • :

  • 对,;您可以使用:

  • :


  • 运行批处理文件时,会出现命令行并写入“输入要发送的消息;在新行上按CTRL-Z结束消息,然后按Enter”?我尝试:@echo off set MESSAGE=系统将重新启动msg murat%MESSAGE%,而不写入@echo off当我从命令行尝试时,它是正常的,但在批处理文件上,它仍然要求我输入消息,并且无法识别定义变量。但echo得到了什么?它在执行什么?当我运行批处理文件时,会出现命令行并写入“输入要发送的消息;在新行上按CTRL-Z结束消息,然后输入”?我尝试:@echo off set MESSAGE=系统将重新启动msg murat%MESSAGE%,而不写入@echo off当我从命令行尝试时,它是正常的,但在批处理文件上,它仍然要求我输入消息,并且无法识别定义变量。但echo得到了什么?它执行的是什么?SLaks的答案是正确的,但我认为你在作业中在
    =
    周围加了空格,破坏了它。答案没有,很好用。谢谢安德烈。标记你的评论。SLaks的答案是正确的,但我认为你在作业中在
    =
    周围加了空格破坏了它。答案没有,很好用。谢谢安德烈。标记您的评论。
    set MESSAGE=System will be restarted 
    msg userE %MESSAGE%
    
    set USERS=(userA userB userC userD userE userF)
    set MESSAGE=System will be restarted 
    
    for %%i in %USERS% do msg %%i %MESSAGE%