Re: [comtypes-users] Creating Shell Links using comtypes
Hi, just to let you know: I gave up on creating .lnk files using comtypes and instead use .url files with a local address. For my application placing such a file in the Windows startup folder they works just fine, and have the huge advantage of being simple text files. Thanks again for the help, Markus - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
Markus Gritsch wrote: Hi, just to let you know: I gave up on creating .lnk files using comtypes and instead use .url files with a local address. For my application placing such a file in the Windows startup folder they works just fine, and have the huge advantage of being simple text files. Sorry I haven't been much help here. I'm deep in the middle of something else or else I'd probably have knocked something up for you. For the record, is there a particular reason why you can't just use one of the pywin32 solutions? TJG - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
Martin (gzlist) schrieb: On 03/11/2008, Markus Gritsch [EMAIL PROTECTED] 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. Cool! The only thing I would suggest to change is to use QueryInterface instead of cast: import comtypes from comtypes.client import CreateObject ws = CreateObject(WScript.Shell) from comtypes.gen import IWshRuntimeLibrary shortcut = ws.CreateShortcut(test_shortcut.lnk).QueryInterface(IWshRuntimeLibrary.IWshShortcut) shortcut.TargetPath = cmd.exe shortcut.Arguments = /K C:\Python24\python.exe shortcut.Save() -- Thanks, Thomas - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
Markus Gritsch schrieb: Hi, just to let you know: I gave up on creating .lnk files using comtypes and instead use .url files with a local address. For my application placing such a file in the Windows startup folder they works just fine, and have the huge advantage of being simple text files. Does the solution that Martin posted not work for you? -- Thanks, Thomas - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
On 05/11/2008, Thomas Heller [EMAIL PROTECTED] wrote: Cool! The only thing I would suggest to change is to use QueryInterface instead of cast: Aha. Thanks, thought there must be an easier way of doing that. On 05/11/2008, Markus Gritsch [EMAIL PROTECTED] wrote: On Wed, Nov 5, 2008 at 1:19 PM, Thomas Heller [EMAIL PROTECTED] wrote: Does the solution that Martin posted not work for you? I am developing on a Windows XP machine, but test the py2exe-packed binaries also on Windows 2000 and Windows 98 virtual machines. You'll be pleased to hear then that I just tried it on a real win98se box, with python 2.4.4/ctypes 1.0.2/comtypes 0.5.2 and it worked fine (after swapping cmd.exe for command.com that is). Traceback (most recent call last): File test.py, line 5, in module AttributeError: 'POINTER(IUnknown)' object has no attribute 'CreateShortcut' Obvious stab-in-the-dark here, try: from comtypes.gen import IWshRuntimeLibrary +ws = ws.QueryInterface(IWshRuntimeLibrary.IWshShell2) shortcut = ws.CreateShortcut(test_shortcut.lnk).QueryInterface( IWshRuntimeLibrary.IWshShortcut) Also make sure you're on the latest comtypes version, I vaugely remember the code generator messing me around a bit before I upgraded (to 0.4.2 that would have been, though). Maybe the version of the Windows Script Host installed there is too old to contain the CreateShortcut functionality. Therefore I would prefer not to depend on the Windows Script Host. This strikes me as a misdiagnosis, problem looks to be with the generated interface, not the underlying library in win98. Martin - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
Markus Gritsch schrieb: Hi, I would like to create shell links (.lnk) from my Python program. I found the following solution at [1] which uses win32com: import os, sys import pythoncom from win32com.shell import shell, shellcon shortcut = pythoncom.CoCreateInstance ( shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink ) shortcut.SetPath (sys.executable) shortcut.SetDescription (Python %s % sys.version) shortcut.SetIconLocation (sys.executable, 0) desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0) persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile) persist_file.Save (os.path.join (desktop_path, python.lnk), 0) I was trying to translate this to comtypes, but had absolutely no success. It would be very nice, if someone could give me any advice how to do this using comtypes. I have now bit the bullet and implemented the IPersistFile (in comtypes.persist), IShellLinkA, IShellLinkW interfaces plus the ShellLink coclass in comtypes SVN. A usage example is at the bottom of the comtypes.shelllink file: http://comtypes.svn.sourceforge.net/viewvc/comtypes/trunk/comtypes/shelllink.py?revision=457view=markup Thomas - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
On Mon, Nov 3, 2008 at 4:29 PM, MR Michael Robellard (5314) [EMAIL PROTECTED] wrote: I don't believe IShellLink uses Dispatch/automation objects, so you will have to import the tlb information Microsoft supplies the idl and h file in shobjidl.idl and shobjidl.h You can use midl to create a tlb from it. Then you should be able to load the tlb into comtypes. Thank you for your directions. I used midl ShObjIdl.idl to generate the ShObjIdl.tlb file. But when I try to load it with comtypes using from comtypes.client import GetModule GetModule('ShObjIdl.tlb') I get the following output: # Generating comtypes.gen._50A7E9B1_70EF_11D1_B75A_00A0C90564FE_0_1_0 # Generating comtypes.gen._00020430___C000_0046_0_2_0 # Generating comtypes.gen.stdole C:\Python25\lib\site-packages\comtypes\tools\codegenerator.py:477: UserWarning: Structure __MIDL_IOleAutomationTypes_0004: PACKING FAILED: total alignment (8/64) warnings.warn(message, UserWarning) Traceback (most recent call last): File auto.py, line 11, in module shell = GetModule( 'ShObjIdl.tlb' ) File C:\Python25\lib\site-packages\comtypes\client\_generate.py, line 112, in GetModule mod = _CreateWrapper(tlib, pathname) File C:\Python25\lib\site-packages\comtypes\client\_generate.py, line 187, in _CreateWrapper mod = _my_import(fullname) File C:\Python25\lib\site-packages\comtypes\client\_generate.py, line 26, in _my_import return __import__(fullname, globals(), locals(), ['DUMMY']) File C:\Python25\lib\site-packages\comtypes\gen\_50A7E9B1_70EF_11D1_B75A_00A0C90564FE_0_1_0.py, line 1101, in module assert sizeof(__MIDL_IOleAutomationTypes_0004) == 16, sizeof(__MIDL_IOleAutomationTypes_0004) AssertionError: 8 Any hints? Kind regards, Markus - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
On 03/11/2008, Markus Gritsch [EMAIL PROTECTED] 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 - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
We use win32com for our shortcut creation as well. One thin I noticed that is different in you code compared to ours is that we pass true as the second parameter to persist_file.Save To be more helpful I think we would need to know where your code is dying, and what error messages you are getting. -Original Message- From: Markus Gritsch [mailto:[EMAIL PROTECTED] Sent: Monday, November 03, 2008 9:11 AM To: comtypes-users@lists.sourceforge.net Subject: [comtypes-users] Creating Shell Links using comtypes Hi, I would like to create shell links (.lnk) from my Python program. I found the following solution at [1] which uses win32com: import os, sys import pythoncom from win32com.shell import shell, shellcon shortcut = pythoncom.CoCreateInstance ( shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink ) shortcut.SetPath (sys.executable) shortcut.SetDescription (Python %s % sys.version) shortcut.SetIconLocation (sys.executable, 0) desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0) persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile) persist_file.Save (os.path.join (desktop_path, python.lnk), 0) I was trying to translate this to comtypes, but had absolutely no success. It would be very nice, if someone could give me any advice how to do this using comtypes. Kind regards, Markus [1] http://tgolden.sc.sabren.com/python/win32_how_do_i/create-a-shortcut.htm l - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users
Re: [comtypes-users] Creating Shell Links using comtypes
I don't believe IShellLink uses Dispatch/automation objects, so you will have to import the tlb information Microsoft supplies the idl and h file in shobjidl.idl and shobjidl.h You can use midl to create a tlb from it. Then you should be able to load the tlb into comtypes. -Original Message- From: Markus Gritsch [mailto:[EMAIL PROTECTED] Sent: Monday, November 03, 2008 9:51 AM To: comtypes-users@lists.sourceforge.net Subject: Re: [comtypes-users] Creating Shell Links using comtypes On Mon, Nov 3, 2008 at 3:16 PM, MR Michael Robellard (5314) [EMAIL PROTECTED] wrote: To be more helpful I think we would need to know where your code is dying, and what error messages you are getting. I tried the following: import sys import comtypes from comtypes.client import CreateObject CLSID_ShellLink = '{00021401---C000-0046}' IID_IShellLink = '{000214EE---C000-0046}' shortcut = CreateObject(CLSID_ShellLink, comtypes.CLSCTX_INPROC_SERVER) shortcut.SetPath(sys.executable) and got an AttributeError: 'POINTER(IUnknown)' object has no attribute 'SetPath' - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users