本帖最后由 0x34 于 2025-1-1 17:05 编辑
使用前要把已登录的微信退掉,不然没有效果
分享下软件源码:
[Golang] 纯文本查看 复制代码 package main
import (
"errors"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"golang.org/x/sync/errgroup"
"golang.org/x/sys/windows/registry"
"log"
"os"
"os/exec"
"path/filepath"
"time"
)
var (
defaultN float64 = 3
)
func main() {
a := app.New()
w := a.NewWindow("微信多开器")
w.SetFixedSize(true)
w.Resize(fyne.NewSize(300, 200))
label := widget.NewLabel(newLabelStr(int(defaultN)))
progress := widget.NewProgressBar()
progress.Resize(fyne.NewSize(300, 20))
progress.Refresh()
slider := widget.NewSlider(1, 10)
slider.Step = 1
slider.Value = defaultN
slider.OnChanged = func(value float64) {
label.SetText(newLabelStr(int(value)))
}
button := widget.NewButton("开始", nil)
button.OnTapped = func() {
button.SetText("打开中...")
for i := 0.1; i <= 1.0; i += 0.15 {
time.Sleep(time.Millisecond * 100)
progress.SetValue(i)
}
err := startMulti(int(slider.Value))
if err != nil {
information := dialog.NewCustom("打开失败", "关闭", widget.NewLabel(""), w)
information.Show()
button.SetText("重试")
} else {
information := dialog.NewCustom("打开成功", "关闭", widget.NewLabel(""), w)
information.Show()
button.SetText("打开成功")
button.Disable()
}
}
aboutLink := widget.NewHyperlink("关于", nil)
aboutLink.OnTapped = func() {
showAboutWindow(a)
}
aboutContainer := container.NewCenter(aboutLink)
content := container.NewVBox(
label,
slider,
progress,
button,
aboutContainer,
)
w.SetContent(content)
w.ShowAndRun()
}
func showAboutWindow(app fyne.App) {
aboutWin := app.NewWindow("关于")
aboutContent := widget.NewLabel("作者: 0x34\n发布时间: 2024-12")
aboutWin.SetContent(aboutContent)
aboutWin.Resize(aboutContent.MinSize())
aboutWin.Show()
}
func startMulti(n int) error {
var eg errgroup.Group
for i := 0; i < n; i++ {
eg.Go(startWeChat)
}
return eg.Wait()
}
func startWeChat() error {
path, err := getWeChatInstallPath()
if err != nil {
return err
}
wechatEXE := filepath.Join(path, "wechat.exe")
log.Default().Println("wechatEXE: ", wechatEXE)
if _, err := os.Stat(wechatEXE); errors.Is(err, os.ErrNotExist) {
return err
}
cmd := exec.Command(wechatEXE)
err = cmd.Start()
if err != nil {
return err
}
return nil
}
func getWeChatInstallPath() (string, error) {
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Tencent\WeChat`, registry.QUERY_VALUE)
if err != nil {
return "", err
}
defer key.Close()
val, _, err := key.GetStringValue("InstallPath")
if err != nil {
return "", err
}
return val, nil
}
func newLabelStr(n int) string {
return fmt.Sprintf("多开数量: %d", n)
}
|