Página 1 de 1

Icono de un acceso directo procedente de una DLL

Publicado: 17 de abril de 2026 - 14:24
por Stan
Hola,

¿sería posible añadir un argumento a setuphelpers para las funciones relacionadas con la creación de accesos directos, permitiendo al usuario elegir un icono de DLL y su índice? Por ejemplo: `

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

Esto permitiría un icono como este : https://renenyffenegger.ch/development/ ... es-100.png (no es la última versión, pero se entiende la idea :D).

¡Gracias de antemano!

Que tengas un buen día.

Stan

Re: Icono de un acceso directo desde una DLL

Publicado: 17 de abril de 2026 - 14:54
por dcardon
Hola Stan,

creo que esto es demasiado específico para integrarlo directamente en la función `create_desktop_shortcut`.

Sin embargo, ¿por qué no añadir una función de extracción de iconos a los setuphelpers para `update_package`? :-)

Ya lo hemos hecho con una solución personalizada en un paquete interno para un cliente. Veré si es algo que se pueda generalizar.

Saludos,

Denis

Re: Icono de un acceso directo desde una DLL

Publicado: 17 de abril de 2026 - 15:45
por Stan
Buen día,

Gracias por su respuesta.
Tras investigar el código de setuphelpers, me di cuenta de que en realidad era bastante simple (o al menos eso supongo).

Si observamos la función de creación de accesos directos (https://www.wapt.fr/apidoc/wapt-2.6/win ... e_shortcut)
Encontramos dos lugares (en las últimas 3 líneas que he comentado) en relación con este índice, supongo que lo único que faltaría es añadir el argumento.

Código: Seleccionar todo

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 
Todo lo que se necesitaría es esto (?):

Código: Seleccionar todo

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), '') 
Gracias de antemano !