I've written a Python program which uses comtypes/ctypes to create a shortcut and saves it in the Startup folder. In development mode, everything works great but when the program is built using py2exe and run, the following error occurs:
(-2147024891, 'Access is denied.', (None, None, None, 0, None))
os is winxp sp3, the code goes like this:
shellObj = CreateObject(ShellLink)
shortcut = shellObj.QueryInterface(IShellLinkW)
shortcut.SetWorkingDirectory(os.path.dirname(sys.executable))
shortcut.SetPath(link_target)
shortcut.SetDescription(link_desc)
pf = shellObj.QueryInterface(IPersistFile)
Try:
pf.Save(link_loc + link_file_name, True)
except Exception as ex:
print ex
finally:
pf.Release()
shortcut.Release()
If I persist the shortcut to any ordinary folder other than startup, no problems occur.