英文:
Mass sending message via CMD
问题
Sure, here's the translated part of your text:
我正在尝试创建一个批处理文件,它可以让我通过命令提示符向大量用户发送消息。因为我是编程新手,会感激任何帮助。谢谢。
目前我的代码如下。
@ECHO OFF
MSG /SERVER:hostname1 /TIME:60 /v /w * 你好用户,请更新您的笔记本电脑 *
echo 消息已发送
MSG /SERVER:hostname2 /TIME:60 /v /w * 你好用户,请更新您的笔记本电脑 *
echo 消息已发送
MSG /SERVER:hostname3 /TIME:60 /v /w * 你好用户,请更新您的笔记本电脑 *
echo 消息已发送
暂停
ECHO ON
我有很多主机名,因此我想让生活变得更容易。
我正在尝试编写类似于这样的代码。
@ECHO OFF
SET hostname=hostname1, hostname2, hostname3
SET message=你好用户,请更新您的笔记本电脑
MSG /SERVER:%hostname% /TIME:60 /v /w * %message%
echo 消息已发送
暂停
ECHO ON
<details>
<summary>英文:</summary>
I'm trying to create a batch file which allow me to send message to mass users via cmd. Would appreciate any help as Im new to coding. Thank you.
Currently my code is like this.
@ECHO OFF
MSG /SERVER:hostname1 /TIME:60 /v /w * Hello User, Please update your laptop *
echo message send
MSG /SERVER:hostname2 /TIME:60 /v /w * Hello User, Please update your laptop *
echo message send
MSG /SERVER:hostname3 /TIME:60 /v /w * Hello User, Please update your laptop *
echo message send
pause
ECHO ON
-------------------------------------------------------------
I have a lot of hostnames thus I want to make my life easier.
I'm trying to have a code something like this.
@ECHO OFF
SET hostname=hostname1, hostname2, hostname3
SET message=Hello User, Please update your laptop
MSG /SERVER:%hostname% /TIME:60 /v /w * %message%
echo message send
pause
ECHO ON
</details>
# 答案1
**得分**: 0
```bat
@ECHO OFF
SET hostnames="hostname1","hostname2","hostname with spaces"
SET message=你好,用户,请更新您的笔记本
FOR %%i IN (%hostnames%) DO (
MSG /SERVER:%%i /TIME:60 /v /w %message%
echo message send to %%i
)
pause
英文:
You'll need to create a loop to send the message to each hostname one by one.
In this code, we use the FOR loop to iterate over each hostname in the hostnames variable.
The MSG command is executed for each hostname
<!-- language: lang-bat -->
@ECHO OFF
SET hostnames="hostname1","hostname2","hostname with spaces"
SET message=Hello User, Please update your laptop
FOR %%i IN (%hostnames%) DO (
MSG /SERVER:%%i /TIME:60 /v /w %message%
echo message send to %%i
)
pause
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论