From: Martin (gzlist) <gz...@go...> - 2008-11-04 10:10:17
|
On 03/11/2008, Markus Gritsch <m.g...@gm...> wrote: > Hi, > > I would like to create shell links (.lnk) from my Python program. > ... > It would be very nice, if someone could give me any advice > how to do this using comtypes. When I wanted to do this in a hurry and didn't have time to look up the right way to do it, I ended up with code something like: import comtypes from comtypes.client import CreateObject ws = CreateObject("WScript.Shell") from comtypes.gen import IWshRuntimeLibrary shortcut = comtypes.cast(ws.CreateShortcut("test_shortcut.lnk"), comtypes.POINTER(IWshRuntimeLibrary.IWshShortcut)) shortcut.TargetPath = "cmd.exe" shortcut.Arguments = "/K C:\Python24\python.exe" shortcut.Save() This worked for me, but may be bad practice or generally bogus in some way or other. I think I got there by reading <http://www.ironpython.info/index.php/Creating_a_Shortcut_File_with_WSH_Interop> then looking at the comtypes generated code, then poking things until it stopped throwing exceptions. Martin |