1

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
Rabih Kodeih
  • 9,361
  • 11
  • 47
  • 55

2 Answers2

1

Run your py2exe program with administrator privileges.

P'sao
  • 2,946
  • 11
  • 39
  • 48
1

Solved, the problem was that Commodo security center was blocking access to the aforementioned folder. So I just added the app to the trust list. As for the R6034 error, I just had to make sure to imbed the following in py2exe manifest xml section:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity 
          type="win32" 
          name="Microsoft.VC90.CRT" 
          version="9.0.21022.8" 
          processorArchitecture="x86" 
          publicKeyToken="1fc8b3b9a1e18e3b">
      </assemblyIdentity>
    </dependentAssembly>
  </dependency>

and adding msvcr90.dll and msvcp90.dll to the same installation folder as the exe (SxS configuration) making sure that the version and publicKeyToken match exactly those mentioned in the Microsoft.VC90.CRT.manifest file which is usually bundled with those dlls. I don't have Visual Studio installed.

Rabih Kodeih
  • 9,361
  • 11
  • 47
  • 55