如何批量给局域网内网里的电脑发送信息
使用 PowerShell 发送消息
Windows 系统内置的 msg
命令可以通过 PowerShell 批量发送消息。以下是一个示例脚本,假设目标计算机名存储在 computers.txt
文件中:
$computers = Get-Content "computers.txt"
$message = "这是测试消息,请忽略。"foreach ($computer in $computers) {if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {msg * /SERVER:$computer $message} else {Write-Host "$computer 无法连接"}
}
使用 NetSend 替代工具
Windows 10/11 移除了经典的 net send
功能,可以改用第三方工具如 NetSend 或 MsgTool。以下是使用 NetSend 的示例:
netsend.exe /d:192.168.1.* /m:"紧急通知:系统将于今晚维护"
通过 WMI 远程执行命令
使用 WMI 在目标机器上弹出消息框:
$computers = "PC1", "PC2", "PC3"
$message = "重要通知:请保存工作"foreach ($comp in $computers) {Invoke-WmiMethod -ComputerName $comp -Class Win32_Process -Name Create -ArgumentList "msg * '$message'"
}
利用共享文件夹广播
创建一个共享文件夹,所有计算机设置开机脚本检测该文件夹下的新消息文件:
rem 发送端
echo "周五下午3点会议" > \\server\share\newmsg.txtrem 接收端脚本
if exist \\server\share\newmsg.txt (for /f "delims=" %%i in (\\server\share\newmsg.txt) do msg * %%idel \\server\share\newmsg.txt
)
使用 Python 跨平台方案
安装 pywin32
库后可以通过 Python 实现:
import win32net
import win32netconcomputers = ["pc1", "pc2"]
message = "系统升级通知"for pc in computers:try:win32net.NetMessageBufferSend(None, pc, None, message)except Exception as e:print(f"发送到 {pc} 失败: {str(e)}")
注意事项
- 确保所有目标计算机启用了 Messenger 服务(Windows 10需手动安装)
- 防火墙需允许 UDP 端口 135-139 和 TCP 445 通信
- 域环境建议使用组策略统一部署接收脚本
- 对 macOS/Linux 设备需改用 SSH 或自定义 UDP 广播方案