18

I am using cx-freeze to create an MSI installer for a Python application. How can I install a link to the application from the desktop?

2

1 Answer 1

36

To create a shortcut to the application, give the shortcut_name and shortcut_dir options to the Executable. The shortcut_dir can name any of the System Folder Properties (thanks Aaron). For example:

from cx_Freeze import *

setup(
    executables = [
        Executable(
            "MyApp.py",
            shortcut_name="DTI Playlist",
            shortcut_dir="DesktopFolder",
            )
        ]
    )

You can also add items to the MSI Shortcut table. This lets you create multiple shortcuts and set the working directory (the "start in" setting of the shortcut).

from cx_Freeze import *

# http://msdn.microsoft.com/en-us/library/windows/desktop/aa371847(v=vs.85).aspx
shortcut_table = [
    ("DesktopShortcut",        # Shortcut
     "DesktopFolder",          # Directory_
     "DTI Playlist",           # Name that will be show on the link
     "TARGETDIR",              # Component_
     "[TARGETDIR]playlist.exe",# Target exe to exexute
     None,                     # Arguments
     None,                     # Description
     None,                     # Hotkey
     None,                     # Icon
     None,                     # IconIndex
     None,                     # ShowCmd
     'TARGETDIR'               # WkDir
     )
    ]

# Now create the table dictionary
msi_data = {"Shortcut": shortcut_table}

# Change some default MSI options and specify the use of the above defined tables
bdist_msi_options = {'data': msi_data}

setup(
    options = {
        "bdist_msi": bdist_msi_options,
    },
    executables = [
        Executable(
            "MyApp.py",
            )
        ]
    )
9
  • Would you know how this works with a system administrator going to install such an app? They won't get the option for shortcuts or will they? Oct 23, 2013 at 7:25
  • 1
    The shortcut will be installed for all users if the ALLUSERS property is set. Nov 3, 2013 at 20:50
  • 1
    One way to set ALLUSERS is to add "ALLUSERS=1" to the msiexec command line when installing the .MSI. Jan 25, 2014 at 17:30
  • 2
    Here's a list of Windows folders which you can use with shortcutDir: msdn.microsoft.com/en-us/library/…
    – Aaron
    Apr 30, 2014 at 15:45
  • 1
    @Har Yes, you can create multiple desktop shortcuts by adding multiple items to the shortcut_table list. Use a different "shortcut" name for each item. Feb 19, 2015 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.