Before running the code, download the wftools library with the following command:
pip install wftools
After installation, use the wftools module:
import wftools
soft_path = r"D:\ 微信 \WeChat\WeChat.exe"
wftools.open_soft(soft_path=soft_path, num=2)
Here, replace soft_path with the storage location of WeChat.exe on your computer, and replace num with the number of WeChat instances you want to open.
Graphical interface version:
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("WeChat Multi-Opening Tool")
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="Quantity:", 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="Start", command=start_program, font=("Arial", 12), bg="lightblue", fg="white")
start_button.pack(pady=10)
root.mainloop()
First, we create a function called handle_drag to handle file drag and drop events. When a user drags and drops files onto the window, this function clears the contents of the text box and processes each dropped file one by one. For each file, it decodes the file path as GBK encoding and uses the get_shortcut_target function to get the target path of the shortcut. Then, it inserts the target path into the text box.
Next, we define a function called get_shortcut_target to get the target path of a shortcut. It uses the win32com library to create a WScript.Shell object and uses the CreateShortcut method of that object to get the target path of the shortcut.
Then, we define a function called start_program to start the program. It first gets the user input for the quantity of programs to start from the input box and gets the program path from the text box. Then, it calls the open_soft function from the wftools library, passing the program path and quantity as parameters to start the specified number of programs.
Next, we create a Tkinter root window object and set the title, size, and resizable properties of the window.
Then, we create a text box object to display the file paths.
After that, we associate the file drag and drop event with the handle_drag function using the hook_dropfiles function from the windnd library.
Then, we create a label and an entry box for the user to input the quantity of programs to start.
Finally, we create a button to trigger the start_program function.
Lastly, we call root.mainloop() to start the event loop of the program, allowing the GUI interface to respond to user actions.
Usage:
-
Drag and drop the desktop WeChat icon: Drag and drop the shortcut files of the programs you want to start into the window, and the file paths will be displayed in the text box.
-
Enter the quantity to start: Enter the number of programs you want to start in the quantity input box. The default is 2. Click "Start" to enable the multi-opening WeChat functionality.