NT: Create a link

Gary Herron gherron at aw.sgi.com
Thu Apr 22 12:33:17 EDT 1999


Holger Jannsen wrote:
> 
> Hi,
> 
> I'd like to know how to create a link to a file with python under WinNT?
> Perhaps there is a possibility to get access to 'IShellLink' (Win32Api)?
> 
> Thank you,
> Holger
> (new under this snake;-))

This is a short python program provided by Mark Hammond (the author of
win32com and friends) in response to a similar question some few weeks
ago.

# MakeShortcut.py
# A demo of how to create a shortcut using Python.

# This code makes a shortcut to sys.argv[0] in the root directory.

from win32com.shell import shell
import pythoncom

def CreateIt(fileName):
 # 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( fileName )
 sh.SetDescription("A test link created with Python")

 # Save the link itself.
 persist.Save("\\PythonTest.lnk", 1)

if __name__=='__main__':
 import sys
 CreateIt(sys.argv[0])


-- 
Dr. Gary Herron <gherron at aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101




More information about the Python-list mailing list