无法在Windows XP的启动文件夹中保存快捷方式,出现“拒绝访问”COM错误

1 投票
2 回答
721 浏览
提问于 2025-04-17 05:09

我写了一个Python程序,使用comtypes和ctypes来创建一个快捷方式,并把它保存在启动文件夹里。在开发模式下,一切都运行得很好,但当我用py2exe打包程序并运行时,就出现了以下错误:

(-2147024891, '访问被拒绝。', (None, None, None, 0, None))

我的操作系统是Windows XP SP3,代码大致是这样的:

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()

如果我把快捷方式保存到其他普通文件夹,而不是启动文件夹,就没有任何问题。

2 个回答

1

以管理员权限运行你的py2exe程序。

1

问题解决了,原来是Commodo安全中心阻止了我访问那个文件夹。所以我把这个应用程序添加到了信任列表里。至于R6034错误,我只需要在py2exe的清单xml部分加上以下内容:

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

然后把msvcr90.dll和msvcp90.dll这两个文件放到和exe文件同一个安装文件夹里(这是SxS配置),确保它们的版本和publicKeyToken完全和Microsoft.VC90.CRT.manifest文件中提到的一样,这个文件通常会和这些dll一起打包。我没有安装Visual Studio。

撰写回答