# -*- coding: iso-8859-1 -*- #. // _by_CreateShortcut.py #. // Crée un raccourci pour un lancer programme. from os.path import isfile from os import remove from win32com.client import Dispatch def by_CreateShortcut( cPathName , cTarget , cDirWork , cArguments = None , cIcon = None , cHotkey = None , nWindowStyle = 1 , cDescription = "Raccourci créé avec Python" ): if isfile( cPathName + ".lnk" ): remove( cPathName + ".lnk" ) #. endif oShell = Dispatch( "WScript.Shell" ) # // CreateObject() refuse oLink.Save(). oLink = oShell.CreateShortcut( cPathName + ".lnk" ) oLink.TargetPath = '"' + cTarget + '"' oLink.WorkingDirectory = '"' + cDirWork + '"' if not cArguments is None: oLink.Arguments = cArguments #. endif if not cIcon is None: if isfile( cIcon ): oLink.IconLocation = cIcon #. endif #. endif if not cHotkey is None: oLink.Hotkey = cHotkey #. endif oLink.WindowStyle = nWindowStyle oLink.Description = cDescription oLink.Save() oShell = None return 0 ''' Dernière modification : 2022-02-16 [Exemple] import sys sys.path.append( "modules" ) from _by_CreateShortcut import by_CreateShortcut # // Crée un raccourci pour un lancer programme. from _by_dirbase import by_dirbase # // Renvoie le dossier par défaut avec ou sans << \ >> à la fin. from _by_msgbox import by_msgbox # // Boîte de dialogue avec options et valeur de retour. from _by_msgbox import MB_ICONINFORMATION # // Une icône composée d'une lettre minuscule i dans un cercle bleu apparaît dans la boîte de message. #. // sys.executable = Dossier et exe de Python. #. // sys.argv[ 0 ] = Nom du script en cours d'exécution dans son dossier. by_CreateShortcut( by_dirbase() + "_Lance" , sys.executable , by_dirbase( False) , sys.argv[ 0 ] , "D:\\$Tools\\Icone\\Roxanne.ico" ) by_msgbox( "Fin du programme", "by_CreateShortcut()", MB_ICONINFORMATION ) [/Exemple] '''