Set WshShell = WScript.CreateObject("WScript.Shell")
' 打开微信(假设微信在桌面有快捷方式)
WshShell.Run "wechat"
WScript.Sleep 2000 ' 等待微信启动
' 激活微信窗口
WshShell.AppActivate "微信"
WScript.Sleep 500
' 模拟Ctrl+F打开搜索
WshShell.SendKeys "^f"
WScript.Sleep 500
' 输入联系人姓名
WshShell.SendKeys "联系人名称"
WScript.Sleep 1000
' 回车进入聊天窗口
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
' 输入消息内容
WshShell.SendKeys "这是自动发送的消息{ENTER}"
WScript.Echo "消息发送完成!"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True ' 设置为False可以隐藏窗口
ie.Navigate "https://wx.qq.com/"
WScript.Sleep 5000 ' 等待页面加载,需手动扫码登录
' 登录后可以继续自动化操作...
创建一个Python脚本,然后通过VBS调用:
wechat_send.py:
import pyautogui
import time
import sys
def send_wechat_message(contact, message):
# 打开微信快捷键 Win+4(假设微信固定在任务栏第4位)
pyautogui.hotkey('win', '4')
time.sleep(2)
# 搜索联系人
pyautogui.hotkey('ctrl', 'f')
time.sleep(1)
pyautogui.write(contact)
time.sleep(1)
pyautogui.press('enter')
time.sleep(1)
# 发送消息
pyautogui.write(message)
pyautogui.press('enter')
if __name__ == "__main__":
send_wechat_message(sys.argv[1], sys.argv[2])
调用Python的VBS脚本:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "python wechat_send.py ""好友名称"" ""消息内容""", 0, False
' 企业微信机器人webhook示例
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=你的KEY"
data = "{""msgtype"":""text"",""text"":{""content"":""Hello World""}}"
objHTTP.Open "POST", url, False
objHTTP.setRequestHeader "Content-Type", "application/json"
objHTTP.Send data
WScript.Echo "发送状态:" & objHTTP.Status
' 定时发送消息
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
currentTime = Time
If currentTime = #09:00:00 AM# Then ' 每天9点发送
WshShell.Run "python wechat_send.py ""老板"" ""早上好!"""
WScript.Sleep 60000 ' 发送后等待1分钟,避免重复发送
End If
WScript.Sleep 1000 ' 每秒检查一次时间
Loop
注意:自动化操作可能违反微信使用条款,请仅用于合法合规的个人用途,并避免频繁操作以免账号受限。