Win32api.... can it create a Windows shortcut (.lnk) file?
Stefan Migowsky
smigowsky at dspace.de
Thu Nov 11 02:38:41 EST 1999
Hi
Mark Hammond did a great job on wrapping the win32api. So
creating a shortcut is just so easy :
################ CreateShortCut.py ####################
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)
Stefan
Dipl.-Physiker Stefan Migowsky
dSPACE GmbH
Technologiepark 25 33100 Paderborn (Germany)
mailto:smigowsky at dspace.de http://www.dspace.de
-----Original Message-----
From: me [mailto:none at fake.net]
Sent: Thursday, November 11, 1999 7:54 AM
To: python-list at python.org
Subject: Win32api.... can it create a Windows shortcut (.lnk) file?
I'm just trying to find an easy to create shortcuts on Windows platforms
through Python... it doesn't seem to be a simple matter though.
I've gone
through all the Win32 docs, and found nothing, and have started writing
(with limited success) a C function to do it.
Is there an easy way? q:]
Thanks,
Kevin Cazabon
kcazabon at home.com
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list