Icon of a shortcut sourced from a DLL

Share your experience and thoughts about WAPT here / Come here and talk about your experience with Wapt, your opinion and your wishes
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is provided on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version (1.8.2 / 2.0 / 2.1 / 2.2 / etc.) AS WELL AS the Enterprise / Discovery edition.
* Specify the server OS (Linux / Windows) and version (Debian Stretch/Buster - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine (Windows 7 / 10)
. * As with any community forum, support is provided voluntarily by members. If you require sales support, you can contact the Tranquil IT sales department at 02.40.97.57.55
Answer
stan
Messages: 17
Registration: May 26, 2025 - 10:16 p.m.

April 17, 2026 - 2:24 PM

Hello,

would it be possible to add an argument to the setuphelpers for functions related to creating shortcuts, allowing the user to choose a DLL icon and its index? For example: `

create_desktop_shortcut(label="Test", target="ms-settings:network-airplanemode", icon_dll="C:\Windows\System32\imageres.dll", index_dll=100)`

This would allow for an icon like this one : https://renenyffenegger.ch/development/ ... es-100.png (it's not the latest version, but you get the idea :D).

Thanks in advance!

Have a good day.

Stan
User avatar
dcardon
WAPT Expert
Messages: 1929
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

April 17, 2026 - 2:54 PM

Hi Stan,

I think this is a bit too specific to be integrated directly into the `create_desktop_shortcut` function.

However, why not add an icon extraction function to the setuphelpers for the `update_package`? :-)

We've already done this with a custom solution in an internal package for a client. I'll see if it's something that can be generalized.

Regards,

Denis
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
stan
Messages: 17
Registration: May 26, 2025 - 10:16 p.m.

April 17, 2026 - 3:45 PM

Good morning,

Thank you for your reply.
After researching the setuphelpers code, I noticed that it was actually quite simple (or at least I assume so).

If we look at the shortcut creation function (https://www.wapt.fr/apidoc/wapt-2.6/win ... e_shortcut)
We find two places (in the last 3 lines I have commented) in relation to this index, all that would be missing is to add the argument I suppose.

Code: Select all

def create_shortcut(path, target='', arguments='', wDir='', icon=''):
    r"""Create a windows shortcut

    Args:
        path (str) : As what file should the shortcut be created?
        target (str): What command should the desktop use?
        arguments (str): What arguments should be supplied to the command?
        wdir (str) : working directory. What folder should the command start in?
        icon (str or list) : filename or (filename, index) (only for file sc)
                              What icon should be used for the shortcut

    Returns:
        None

    >>> create_shortcut(r'c:\\tmp\\test.lnk',target='c:\\wapt\\waptconsole.exe')
    """
    ext = os.path.splitext(path)[1].lower()
    if ext == '.url':
        with open(path, 'w') as shortcut:
            shortcut.write('[InternetShortcut]\n')
            shortcut.write('URL=%s\n' % target)
            shortcut.write('IconFile="%s"\n' % icon)
            shortcut.write('IconIndex=0\n') # ICI
    else:
        winshell.CreateShortcut(path, target, arguments, wDir, (icon, 0), '')# ET ICI 
All that would be needed is this (?):

Code: Select all

def create_shortcut(path, target='', arguments='', wDir='', icon='', index_icon=''):
    r"""Create a windows shortcut

    Args:
        path (str) : As what file should the shortcut be created?
        target (str): What command should the desktop use?
        arguments (str): What arguments should be supplied to the command?
        wdir (str) : working directory. What folder should the command start in?
        icon (str or list) : filename or (filename, index) (only for file sc)
                              What icon should be used for the shortcut

    Returns:
        None

    >>> create_shortcut(r'c:\\tmp\\test.lnk',target='c:\\wapt\\waptconsole.exe')
    """
    ext = os.path.splitext(path)[1].lower()
    index_icon = index_icon if os.path.splitext(icon)[1].lower() == '.dll' else 0 
    if ext == '.url':
        with open(path, 'w') as shortcut:
            shortcut.write('[InternetShortcut]\n')
            shortcut.write('URL=%s\n' % target)
            shortcut.write('IconFile="%s"\n' % icon)
            shortcut.write('IconIndex="%s"\n' % index_icon)
    else:
        winshell.CreateShortcut(path, target, arguments, wDir, (icon, index_icon), '') 
Thanks in advance !
Answer