Documentation of how to create desktop or program menu shortcut in Windows

Issue #48 new
Craig McQueen
created an issue

It would be good to document how to create a desktop shortcut and/or a program menu shortcut with cx_Freeze bdist_msi in Windows.

I found these:

These are good because they explain that option shortcutDir must be set to "DesktopFolder" or "ProgramMenuFolder". But neither make it clear how to put shortcuts in sub-folders (or sub-menus).

That StackOverflow question has an interesting answer about MSI Shortcut tables, but alas, I can't figure out what to put in for icons, subfolders, etc, or how to add to the programs menu.

Comments (2)

  1. Anonymous

    You can use http://msdn.microsoft.com/en-us/library/windows/desktop/aa371847(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/aa370905(v=vs.85).aspx#System_Folder_Properties

    If you wish to add to a subdirectory i believe you can do that normal,y and use but use those as the base.

    here is an shortcut table i use in my setup.py

    shortcut_table = [
        ("DesktopShortcut",        # Shortcut
         "DesktopFolder",          # Directory_
         "program",     # Name
         "TARGETDIR",              # Component_
         "[TARGETDIR]main.exe",   # Target
         None,                     # Arguments
         None,                     # Description
         None,                     # Hotkey
         None,                     # Icon
         None,                     # IconIndex
         None,                     # ShowCmd
         'TARGETDIR'               # WkDir
         ),
    
        ("StartupShortcut",        # Shortcut
         "StartupFolder",          # Directory_
         "program",     # Name
         "TARGETDIR",              # Component_
         "[TARGETDIR]main.exe",   # Target
         None,                     # Arguments
         None,                     # Description
         None,                     # Hotkey
         None,                     # Icon
         None,                     # IconIndex
         None,                     # ShowCmd
         'TARGETDIR'               # WkDir
         ),
    
        ]
    
    msi_data = {"Shortcut": shortcut_table}  # This will be part of the 'data' option of bdist_msi
    

    Hopefully you can use those as examples, if you wished to add to a sub folder you should take a look into http://msdn.microsoft.com/en-us/library/windows/desktop/aa368295(v=vs.85).aspx

    If you use cx_freeze for the icon, and you're shortcuts just link to the cx_freeze created file, it will share the icon, so i don't think you should worry too much about that.

    You might be able to add in the directory table by putting it as part of msi_data, under the key "Directory" and if that works, it will be fairly simple for you to get it to work, as shown in http://www.itninja.com/question/create-a-subfolder-for-my-shortcuts

  2. Craig McQueen reporter

    I make a Directory table as follows:

    directory_table = [
        (
            "ProgramMenuFolder",
            "TARGETDIR",
            ".",
        ),
        (
            "MyProgramMenu",
            "ProgramMenuFolder",
            "MYPROG~1|My Program",
        ),
    ]
    
    msi_data = {
        "Directory": directory_table,
    }
    

    In the setup() call I add:

        options = {
            'bdist_msi': {
                'data': msi_data,
                ...
            },
            ...
        }
    

    Then for my Executable I have:

        executables = [
            Executable(
                "my-program.py",
                copyright="Copyright (C) 2017 My Company Pty Ltd",
                base=base,
                icon="my-program-icon.ico",
                shortcutName="My Program Name",
                shortcutDir="MyProgramMenu",
            ),
        ],
    
  3. Log in to comment