set wshshell=wscript.createobject("wscript.shell")
:User
msgbox "输入您发消息的目标电脑IP地址:",64,"提示"
dim a
a = inputbox("目标电脑IP:","输入目标IP","192.168.31.")
:Send
dim b
b = inputbox("输入您要发送的内容(重新输入目标IP或计算机名请按0):","输入内容")
if b="0" then
wshshell.Run "goto User"
End if
wshshell.Run"cmd.exe /c msg /server "&a&" * "&b&" & pause"
wshshell.Run"goto Send"
if a="exit" then
wshshell.Run"cmd.exe /c taskkill /f /im wscript.exe"
End if
if b="exit" then
wshshell.Run"cmd.exe /c taskkill /f /im wscript.exe"
End if
参考GPT和自己的思路:
看起来代码中存在一个错误,可能是因为InputBox 函数的返回类型与 wshshell.Run 函数接受的参数类型不匹配。
要解决这个问题,可以尝试使用 CStr() 函数将返回的IP地址转换为字符串类型,例如:
a = CStr(inputbox("目标电脑IP:","输入目标IP","192.168.31."))
同样的,对于要发送的内容,也需要使用 CStr() 函数将其转换为字符串类型:
b = CStr(inputbox("输入您要发送的内容(重新输入目标IP或计算机名请按0):","输入内容"))
这样做可能会解决“类型不匹配”错误。
把字符串拼接出来的命令单独在命令行运行,看看是否报错