制作 cx_Freeze 以将应用程序添加到初创公司

Make cx_Freeze to add app to startups

如何让 cx_Freeze 使创建的应用程序在 windows 启动时启动?我找不到任何此类问题的答案。

在启动时启动,我的意思是当计算机启动时,程序会自动启动。我也希望在首次使用该程序时自动完成此操作。

您可以使用 win32 库为您的 exe 创建快捷方式并将其放在启动文件夹中。

from win32com.client import Dispatch
import os

dir = r'C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'
name = 'shortcut.lnk'
path = os.path.join(dir, name)
target = '<your exe>'
working_dir = '<working directory>'
icon = '<file to take the icon from, can be your exe>'

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = working_dir
shortcut.IconLocation = icon
shortcut.save()