开发者

Windows 7 defining variable for bat files and msg command

I have a .bat file like that:

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

Can I define a variable for message part as like:

message = System will be restarted 
msg userA message
msg us开发者_运维知识库erB message
msg userC message
msg userD message
msg userE message
msg userF message

Also is it possible to define users as an array? As like:

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

Thanks for your suggestions.

EDIT: I wrote that lines to a bat file:

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

When I click the bat file I got that screenshot:

Windows 7 defining variable for bat files and msg command


  1. Yes; you can use 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%
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜