IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques tierces Python Discussion :

la fonction create_shortcut


Sujet :

Bibliothèques tierces Python

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    24
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 24
    Points : 18
    Points
    18
    Par défaut la fonction create_shortcut
    Bonjour tout le monde.

    Tout ceux qui on suivis l'évolutions de mes messages savent que je cherche pas mal d'information pour créer mon application et là j'ai un problème lié à un autre post. J'en crée un nouveau puisque l'ancien n'est plus d'actualité.

    En effet je cherche par la programmation à créer un raccourci et à le paramètrer. Dans mes recherches (dans l'aide de Python) j'ai trouvé une fonction qui s'appelle : "créate shortcut", mais quand je l'utilise le compilateur m'informe que la fonction est introuvable, ce qui est normal puisque je n'ai pas trouvé le module qui y fait référence.

    On m'a également parlé de l' "IShellLink" de MS mais je ne vois pas comment pouvoir l'utiliser en python.

    Donc ma question serai de savoir si quelqu'un sais utiliser l'une ou l'autre de ses solutions.

    Merci d'avance.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    376
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 376
    Points : 402
    Points
    402
    Par défaut
    Regarde dans la doc du module win32all
    au niveau de win32com.shell ya un exemple. Je te colle ici le début afin que tu vois si ca corespond à tes problèmes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    Example
    To create a PyIShellLink object
     
    from win32com.shell import shell
     
    import pythoncom
     
    shortcut = pythoncom.CoCreateInstance(
     
    	shell.CLSID_ShellLink, None,
     
    	pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
     
    )
     
     
    To load information from existing shortcut file
     
    shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Load( filename )
     
     
    To save information to a file
     
    shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Save( filename, 0 )
     
     
    This documentation class is based on: http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/sdkdoc/shellcc/shell/ifaces/ishelllink/ishelllink.htm With only minor alterations and notations by Mike Fletcher. Errors may be present, read at your own risk. See also: http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/books/win95ui/chpt09-01.htm A tutorial-like introduction, includes brief discussion of non-file linking, and a fairly simple C sample application for file-based linking.
    Après ils décrivent la classe et ces fonctions. J'espère que ça t'aidera !

    Bon courage
    "There are two major products that come out of Berkeley: LSD and UNIX.
    We don't believe this to be a coincidence."
    - Jeremy S. Anderson

    La FAQ Python
    Les cours et tutoriels pour apprendre Python
    Le Forum Python

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2004
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2004
    Messages : 22
    Points : 25
    Points
    25
    Par défaut
    un wrap complet de l'api ici avec un exemple d'utilisation :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    from win32com.shell import shell
    import win32api
    import pythoncom
    import os
    import sys
     
    def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0),
    Description = ""):
        # Get the shell interface.
        sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \
            pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
     
        # Get an IPersist interface
        persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
     
        # Set the data
        sh.SetPath(Target)
        sh.SetDescription(Description)
        sh.SetArguments(Arguments)
        sh.SetWorkingDirectory(StartIn)
        sh.SetIconLocation(Icon[0],Icon[1])
     
        # Save the link itself.
        persist.Save(Path, 1)
     
    if __name__ == "__main__":
    	TempDir = os.environ["TEMP"]
    	WinRoot = os.environ["windir"]
     
    	Path        =  WinRoot    + "\\Profiles\\All Users\\Desktop\\New Link.lnk"
    	Target      =  Pythonroot + "pythonw.exe "
    	Arguments   =  TempDir + "\\test.py"
    	StartIn     =  TempDir
    	Icon        = (Pythonroot + "\\py.ico", 0)
    	Description = "New Link"
     
    	CreateShortCut(Path,Target,Arguments,StartIn,Icon,Description)
    Tout est bon dans le python

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 12/02/2013, 01h08
  2. Fonction API
    Par margilb dans le forum C++Builder
    Réponses: 2
    Dernier message: 08/07/2002, 11h11
  3. Implémentation des fonctions mathématiques
    Par mat.M dans le forum Mathématiques
    Réponses: 9
    Dernier message: 17/06/2002, 16h19
  4. fonction printf
    Par ydeleage dans le forum C
    Réponses: 7
    Dernier message: 30/05/2002, 11h24
  5. FOnction api specifiant la position de la souris
    Par florent dans le forum C++Builder
    Réponses: 4
    Dernier message: 15/05/2002, 20h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo