运行代码之前,下载 wftools 这个库 命令如下:
pip install wftools
安装完毕后,使用 wftools 模块
import wftools
soft_path = r"D:\ 微信 \WeChat\WeChat.exe"
wftools.open_soft(soft_path=soft_path, num=2)
soft_path 这里,改成自己电脑上 WeChat.exe 的存储位置,num 这里,改成你要打开几个微信。
图形界面版本:
import tkinter as tk
import windnd
import win32com.client
import wftools
def handle_drag(files):
text.delete("1.0", "end")
for file in files:
file = file.decode("gbk")
target_path = get_shortcut_target(file)
text.insert("insert", target_path + "\n")
def get_shortcut_target(path):
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
target_path = shortcut.Targetpath
return target_path
def start_program():
quantity = int(quantity_entry.get())
soft_path = text.get("1.0", "end").strip()
wftools.open_soft(soft_path=soft_path, num=quantity)
root = tk.Tk()
root.title("微信多开小工具")
root.geometry("410x200")
root.resizable(False, False) # 固定窗口大小
text = tk.Text(root, width=60, height=3, font=("Arial", 12))
text.pack(padx=10, pady=10)
windnd.hook_dropfiles(root, func=handle_drag)
quantity_label = tk.Label(root, text="启动数量:", font=("Arial", 12))
quantity_label.pack()
quantity_entry = tk.Entry(root, font=("Arial", 12))
quantity_entry.insert(0, "2")
quantity_entry.pack()
start_button = tk.Button(root, text="启动", command=start_program, font=("Arial", 12), bg="lightblue", fg="white")
start_button.pack(pady=10)
root.mainloop()
首先,我们创建了一个名为 handle_drag 的函数,用于处理文件拖放事件。当用户拖放文件到窗口时,该函数会清空文本框中的内容,并逐个处理拖放的文件。对于每个文件,它会将文件路径解码为 GBK 编码,并使用 get_shortcut_target 函数获取快捷方式的目标路径。然后,它将目标路径插入到文本框中。
接下来,我们定义了一个名为 get_shortcut_target 的函数,用于获取快捷方式的目标路径。它使用 win32com 库创建一个 WScript.Shell 对象,并通过该对象的 CreateShortcut 方法来获取快捷方式的目标路径。
然后,我们定义了一个名为 start_program 的函数,用于启动程序。它首先从输入框中获取用户输入的启动数量,并从文本框中获取程序路径。然后,它调用 wftools 库中的 open_soft 函数,传递程序路径和启动数量作为参数,以启动指定数量的程序。
接下来,我们创建了一个 Tkinter 的根窗口对象,并设置了窗口的标题、大小和不可调整大小的属性。
然后,我们创建了一个文本框对象,用于显示文件路径。
接着,我们使用 windnd 库的 hook_dropfiles 函数将文件拖放事件与 handle_drag 函数关联起来。
然后,我们创建了一个标签和一个输入框,用于用户输入启动数量。
最后,我们创建了一个按钮,用于触发 start_program 函数。
最后,我们调用 root.mainloop () 来启动程序的事件循环,使 GUI 界面能够响应用户的操作。
使用方法:
1,拖放桌面微信图标:将需要启动的程序的快捷方式文件拖放到窗口中,文件路径会显示在文本框中。
2,输入启动数量:在数量输入框中输入你想要启动的程序数量。默认为 2。点击启动即可实现多开微信功能。