[python-win32] pywintypes.com_error

Cesar Romani caesar at inmail24.com
Sat Dec 10 15:52:50 CET 2011


What's wrong with the following code?

--------------------
from win32com.shell import shell
import pythoncom, os

class PyShortcut:
   def __init__(self):
     self._base = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
       pythoncom.CLSCTX_INPROC_SERVER,
       shell.IID_IShellLink)
   def load(self, filename):
     self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)
   def save(self, filename):
     self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0)
   def __getattr__(self, name):
     if name != "_base":
       return getattr(self._base, name)

if __name__=='__main__':
   import sys

   shortcut = PyShortcut()
   if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
     shortcut.load(sys.argv[1])
     print '''Shortcut in file %s to
file:\n\t%s\nArguments:\n\t%s\nDescription:\n\t%s\nWorking
Directory:\n\t%s'''%(
       file,
       shortcut.GetPath(shell.SLGP_UNCPRIORITY)[0],
       shortcut.GetArguments(),
       shortcut.GetDescription(),
       shortcut.GetWorkingDirectory()
     )
--------------------

If I try to use it, as in:
python shortcut.py test.c
I get:

--------------------
Traceback (most recent call last):
   File "shortcut.py", line 22, in <module>
     shortcut.load(sys.argv[1])
   File "shortcut.py", line 10, in load
     self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
--------------------

I'm using python 2.7 on Windows 7 Home Premium with
pywin32-216.win32-py2.7

Many thanks in advance,

-- 
Cesar



More information about the python-win32 mailing list