Search code examples
pythonpython-3.xcx-freeze

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.


Solution

  • 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 = 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()