看到大家对于这部分微信自动发送消息实际运行时遇到很多问题,目前微信的界面也变了,这部分代码已经不再适用了。因此针对现在微信界面重新调整了代码。目前适配的微信版本是3.9.6.33。使用依赖如下
.NetFramework 4.8
FlaUI.UIA3 4.0.0
编译好的执行文件
最新源码
FlaUI.UIA3再结合inspect.exe来进行编程,可以支持很多桌面程序的自动化,大家可以自行发挥
代码如下:
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Conditions;
using FlaUI.Core.Definitions;
using FlaUI.Core.Input;
using FlaUI.Core.WindowsAPI;
using FlaUI.UIA3;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
[STAThread]
static void Main(string[] args)
{
//微信主界面窗口从左向右分3分窗口,可以使用inspect.exe 程序来看实际窗口,控件排列
string target = "文件传输助手";
string sendMsg = "hello this is a test " + DateTime.Now.ToString();
if (args.Length != 2)
{
Console.WriteLine("=======================================================================");
Console.WriteLine("WebChatAuto 联系人 发送消息");
Console.WriteLine("注意:联系人和发送消息需要使用双引号包括");
Console.WriteLine("示例:WebChatAuto \"文件传输助手\" \"Hello WebChat\"");
Console.WriteLine("=======================================================================");
}
else
{
target = args[0];
sendMsg = args[1];
}
Process[] processes = Process.GetProcessesByName("WeChat");
if (processes.Count() != 1)
{
Console.

博客介绍了如何使用C#和FlaUI库来自动化控制微信进行消息发送。代码已更新以适配微信3.9.6.33版本,通过附加微信进程、切换到通讯录、搜索联系人、输入文本和发送消息等步骤,实现了自动发送消息的功能。此外,还提供了旧版代码作为对比。
最低0.47元/天 解锁文章
3701





