Pagina 1 di 1

Icona di un collegamento proveniente da una DLL

Pubblicato: 17 aprile 2026 - 14:24
di Stan
Ciao,

sarebbe possibile aggiungere un argomento alle funzioni di setuphelper per la creazione di collegamenti, che permetta all'utente di scegliere l'icona di una DLL e il suo indice? Ad esempio: `

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

Questo permetterebbe di ottenere un'icona come questa : https://renenyffenegger.ch/development/ ... es-100.png (non è l'ultima versione, ma l'idea è chiara :D).

Grazie in anticipo!

Buona giornata.

Stan

Oggetto: Icona di un collegamento da una DLL

Pubblicato: 17 aprile 2026 - 14:54
di dcardon
Ciao Stan,

credo che questa richiesta sia un po' troppo specifica per essere integrata direttamente nella funzione `create_desktop_shortcut`.

Tuttavia, perché non aggiungere una funzione di estrazione delle icone agli helper di configurazione per `update_package`? :-)

Lo abbiamo già fatto con una soluzione personalizzata in un pacchetto interno per un cliente. Vedrò se è qualcosa che si può generalizzare.

Cordiali saluti,

Denis

Oggetto: Icona di un collegamento da una DLL

Pubblicato: 17 aprile 2026 - 15:45
di Stan
Buongiorno,

Grazie per la sua risposta.
Dopo aver esaminato il codice di setuphelpers, ho notato che in realtà era piuttosto semplice (o almeno così suppongo).

Se guardiamo alla funzione di creazione di scorciatoie (https://www.wapt.fr/apidoc/wapt-2.6/win ... e_shortcut)
Troviamo due punti (nelle ultime 3 righe che ho commentato) in relazione a questo indice, tutto ciò che mancherebbe sarebbe aggiungere l'argomento, suppongo.

Codice: Seleziona tutto

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 
Tutto ciò che servirebbe è questo (?):

Codice: Seleziona tutto

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), '') 
Grazie in anticipo !