Icon d'un raccourci provent d'un DLL

Share here your experience and thought about WAPT / Venez ici parlez de votre expérience avec Wapt, votre avis et vos envies
Règles du forum
Règles du forum communautaire
* English support on www.reddit.com/r/wapt
* Le support communautaire en français se fait sur ce forum
* Merci de préfixer le titre du topic par [RESOLU] s'il est résolu.
* Merci de ne pas modifier un topic qui est taggé [RESOLU]. Ouvrez un nouveau topic en référençant l'ancien
* Préciser version de WAPT installée ( 1.8.2 / 2.0 / 2.1 / 2.2 / etc.) AINSI QUE l'édition Enterprise / Discovery
* Préciser OS du serveur (Linux / Windows) et version (Debian Stretch/Buster - CentOS 7 - Windows Server 2012/2016/2019)
* Préciser OS de la machine d'administration/création des paquets (Windows 7 / 10)
* Comme tout forum communautaire, le support est fait bénévolement par les membres. Si vous avez besoin d'un support commercial, vous pouvez contacter le service commercial Tranquil IT au 02.40.97.57.55
stan
Messages : 13
Inscription : 26 mai 2025 - 22:16

17 avr. 2026 - 14:24

Bonjour,

Serait-il possible d'ajouter dans les setuphelpers, pour les fonctions en rapport avec la création de raccourci, un argument qui permettre de choisir une icon d'un DLL et son index, par exemple:

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

Ce qui permettrait d'avoir cette icon https://renenyffenegger.ch/development/ ... es-100.png (bon c'est pas la version récente mais vous avez compris :D)

Merci d'avance !

Bonne journée.

Stan
Avatar de l’utilisateur
dcardon
Expert WAPT
Messages : 1899
Inscription : 18 juin 2014 - 09:58
Localisation : Saint Sébastien sur Loire
Contact :

17 avr. 2026 - 14:54

Bonjour Stan,

c'est je pense un peu trop spécifique pour être intégré directement dans la fonction create_desktop_shortcut.

Mais par contre pourquoi pas rajouter une fonction d'extraction d'icone dans les setuphelpers pour l'update_package :-)

On l'a déjà fait avec un truc custom dans un paquet interne pour un client. Je vais voir si c'est généralisable.

Cordialement,

Denis
Denis Cardon - Tranquil IT
Communiquez autour de vous sur WAPT! Envoyez nous vos url de blog et d'articles dans la catégorie votre avis du forum, nous les mettrons en avant sur le site WAPT
stan
Messages : 13
Inscription : 26 mai 2025 - 22:16

17 avr. 2026 - 15:45

Bonjour,

Merci de la réponse.
Après m'être renseigné sur le code de setuphelpers, j'ai remarqué qu'enfaite c'était tout simple (enfin je le suppose).

Si on regarde le code de création de shortcut (https://www.wapt.fr/apidoc/wapt-2.6/win ... e_shortcut)
On trouve deux endroit (dans les 3 dernières lignes j'ai commenté) par rapport à cette index il manquerait plus qu'à ajouter l'argument je suppose.

Code : Tout sélectionner

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 
Il suffirait juste de faire ça (?) :

Code : Tout sélectionner

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), '') 
Merci d'avance !
Répondre