#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Links in windows with a module or os


    hi

    I just thought of this:

    how would I create a link to an exe for example I want to put a link on the desktop and link it to an exe which is in a C: directory

    since os.path supports a islink method??
    Those people who think they know everything are a great annoyance to those of us who do.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    >>> import pygtk
    Posts
    4
    Rep Power
    0
    mail.python.org

    i don't particularly like win32all, so here's the less pythonic way i've done it.
    Code:
    open('C:\\temp\\ntdesktopshortcut.js','w').write('var WSHShell=WScript.CreateObject("WScript.Shell"); var MyShortcut = WSHShell.CreateShortcut(WSHShell.SpecialFolders("Desktop")+"\\TEST.lnk"); MyShortcut.WorkingDirectory="C:\\"; MyShortcut.Hotkey="Ctrl+Alt+N"; MyShortcut.TargetPath="C:\\ANY\\OLD\\PATH\\executable.exe"; MyShortcut.IconLocation="C:\\ANY\\OLD\\PATH\\icon.ico";if (WSHShell.Popup("Do you want a shortcut to executable on your desktop?\n\n[If you select Yes, my hotkey will be Control + Alt + N.\nIf this hotkey is already mapped to something else, you can change mine or its previous owner\'s hotkey; I won\'t change either for you.]",0,"Hello, good sir knight!",36)==6){MyShortcut.Save();}')	#36=32+4=Question icon + Yes/No buttons; 6=Yes response
    os.popen3('wscript //NoLogo C:\\temp\\ntdesktopshortcut.js')
    more JS info
    you don't necessarily need to set MyShortcut.IconLocation or MyShortcut.WorkingDirectory or MyShortcut.Hotkey.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    how would you do it with win32all
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    >>> import pygtk
    Posts
    4
    Rep Power
    0
    the link to mail.python.org in my previous post...
    http://mail.python.org/pipermail/pyt...er/015688.html

    here, i prettified it:
    Code:
    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.SetDescription(Description)
        sh.SetArguments(Arguments)
        sh.SetWorkingDirectory(StartIn)
        sh.SetIconLocation(Icon[0],Icon[1])
        sh.SetPath(Target)
    
        # Save the link itself.
        persist.Save(Path, 1)
    
    if __name__ == "__main__":
     	Path = "C:\\Documents and Settings\\All Users\\Desktop\\New Link.lnk"
     	
    	Target =  "C:\\Python23\\pythonw.exe "    #where the link points to
    	Arguments =  "C:\\Python23\\python.exe"
    	StartIn =  "D:\\"
    	Icon = ("C:\\Python23\\py.ico", 0)    #the icon path
    	Description = "New Link"
    	print Path
    	
    	CreateShortCut(Path, Target, Arguments, StartIn, Icon, Description)
    Path, Target, StartIn, and Icon must be valid pathnames.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    okay thanks for the help
    Those people who think they know everything are a great annoyance to those of us who do.

IMN logo majestic logo threadwatch logo seochat tools logo