介绍
一个c++练手项目,辅助在电脑端使用多个微信的朋友门打开微信,起了个贱名morechat
软件架构
win/c++ 17
安装教程
- 点击下载软件
- 新建一个文件夹,放到里面
- 点击运行即可
使用说明
- 只支持win,只测试了win10,win11
版本更新
- 完成了控制台版本基本功能
- 添加了版本信息
工具介绍
https://gitee.com/zealoner/wechat-multi-open-tool
原理
检测注册表寻找微信路径/cmd打开软件
下载连接
https://demo.zealoner.site/exe/%E5%BE%AE%E4%BF%A1%E5%A4%9A%E5%BC%80%E5%B7%A5%E5%85%B7.exe
代码
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <windows.h>
#include <tchar.h>
#include <sstream>
#include <filesystem>
using namespace std;
std::string wechat() {
HKEY key;
DWORD pathSize = MAX_PATH;
TCHAR path[MAX_PATH];
LONG result;
string wechat_path;
// 打开注册表键
result = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Tencent\\WeChat"), 0, KEY_READ, &key);
if (result == ERROR_SUCCESS) {
// 读取InstallPath值
result = RegQueryValueEx(key, _T("InstallPath"), NULL, NULL, (LPBYTE)path, &pathSize);
if (result == ERROR_SUCCESS) {
// 输出路径
wechat_path = path;
} else {
wechat_path = "";
}
// 关闭注册表键
RegCloseKey(key);
} else {
wechat_path = "";
std::cout << "Failed to open registry key.\n";
}
return wechat_path;
}
bool checkFileExist(const std::string& filePath) {
return std::filesystem::exists(filePath);
}
int conf_write(int num=0)
{
std::stringstream ss;
ss << num;
std::ofstream outputFile("lock.txt");
if(outputFile.is_open())
{
outputFile << ss.str();
outputFile.close();
return 1;
}
return 0;
}
std::string conf_read()
{
std::ifstream inputFile("lock.txt"); // 创建一个输入流对象,用于读取文件
std::string line;
if (inputFile.is_open()) { // 检查文件是否成功打开
while (std::getline(inputFile, line)) { // 逐行读取
}
inputFile.close(); // 关闭文件
} else {
std::cerr << "Unable to open the file for reading.\n";
}
return line;
}
int main()
{
std::string wechat_path;
std::string start_commd;
int number;
wechat_path = wechat();
// 查询是否存在lock文件
if (checkFileExist("lock.txt")) {
} else {
conf_write();
}
// 第一次使用写入多开个数
if(stoi(conf_read())==0)
{
cout << "第一次使用,请输入需要多开微信的个数" << endl;
cin >> number;
conf_write(number);
}else{
number = stoi(conf_read());
}
if(wechat_path != "")
{
wechat_path.append("\\WeChat.exe");
start_commd = "start ";
start_commd.append(wechat_path);
// cout << start_commd << endl;
for(int i=0;i<number;i++)
{
system(start_commd.c_str());
}
}
return 0;
}