comtypes
comtypes copied to clipboard
comtypes.shelllink example fails on python 3.6.0 64bit
> python -m comtypes.shelllink
Traceback (most recent call last):
File "c:\...\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\...\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\...\lib\site-packages\comtypes\shelllink.py", line 216, in <module>
pf.Save("foo.lnk", True)
_ctypes.COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, None))
<POINTER(IShellLinkW) ptr=0x265b16257d0 at 265b4002cc8>
C:\...\python.exe
('c:\\...\\python.exe', 1)
The same code passes on python 2.7 64bit
The error is coming from the Save method of IPersistFile which expects two arguments
COMMETHOD(
[], HRESULT, 'Save',
(['in'], LPCOLESTR, 'pszFileName'),
(['in'], BOOL, 'fRemember')),
Hmmm... the example you gave is working on my Windows 7 VM:
(py3_test_2)C:\Users\Andrew>python -m comtypes.shelllink
<POINTER(IShellLinkW) ptr=0x2954b70 at 2e592c8>
C:\Users\Andrew\.edm\envs\py3_test_2\python.exe
('C:\\Users\\Andrew\\.edm\\envs\\py3_test_2\\python.exe', 1)
foo.lnk
(py3_test_2)C:\Users\Andrew>python --version
Python 3.6.0 -- Enthought, Inc. (x86_64)
(py3_test_2)C:\Users\Andrew>edm list
# Packages in environment 'py3_test_2'
# prefix: 'C:\Users\Andrew\.edm\envs\py3_test_2'
appdirs 1.4.3-1 enthought/free
comtypes 1.1.2-1 enthought/free
distribute_remove 1.0.0-4 enthought/free
packaging 16.8-2 enthought/free
pip 10.0.1-1 enthought/free
pyparsing 2.2.0-1 enthought/free
setuptools 38.2.5-1 enthought/free
six 1.10.0-1 enthought/free
(py3_test_2)C:\Users\Andrew>
Creates a file foo.lnk
which launches a terminal window.
the example you gave is working on my Windows 7 VM:
I am running Windows 10. I think it did not matter let me check.
It does indeed fail on my Win10 VM, with the error you posted. :/
It does indeed fail on my Win10 VM, with the error you posted. :/
That sounds fun
I found the issue. For some reason the Save method needs the absolute path for the filename on Windows 10 and python 3
This fails
pf = shortcut.QueryInterface(IPersistFile)
pf.Save("foo.lnk", True)
print pf.GetCurFile()
This works
pf = shortcut.QueryInterface(IPersistFile)
pf.Save(os.path.abspath("foo.lnk"), True)
print(pf.GetCurFile())
So what you're saying is.... the parameter was incorrect. 😄
Since I thought that the problem had been resolved, I closed the issue.