Luke Luke - 6 months ago 50
Python Question

Make cx_Freeze to add app to startups

How can I make cx_Freeze to make the app created to start on windows startup? I can't find the answer to any questions like this.

As in start on startup, I mean when the computer boots, the program automatically starts. I also would like this to be done automatically in first use of the program.

Ni. Ni.
Answer

You can use win32 library to create a shortcut to your exe and place it in the startup folder.

from win32com.client import Dispatch
import os

dir = 'C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'
name = 'shortcut.lnk'
path = os.path.join(dir, name)
target = '<your exe>'
wDir = '<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 = wDir
shortcut.IconLocation = icon
shortcut.save()