通过CMD批量发送消息

huangapple go评论53阅读模式
英文:

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&#39;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&#39;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=&quot;hostname1&quot;,&quot;hostname2&quot;,&quot;hostname with spaces&quot;
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

huangapple
  • 本文由 发表于 2023年2月10日 16:58:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定