【问题标题】:How to set shortcut working directory in cx_freeze msi bundle?如何在 cx_freeze msi 包中设置快捷方式工作目录?
【发布时间】:2014-08-03 10:08:14
【问题描述】:

我正在开发一个处理 SQLite3 数据库的 Python 程序。我使用 cx_Freeze 将其作为 MSI 设置文件。

由 cx_Freeze 生成的 .msi 设置文件生成的 Windows 快捷方式不提供快捷方式的工作目录属性。因此,当我使用桌面上创建的快捷方式运行可执行文件时,它会在桌面本身上创建数据库文件。

这可以通过为快捷方式提供不同的工作目录来更改。我该怎么做?

【问题讨论】:

    标签: python windows-installer shortcut


    【解决方案1】:

    我可以通过对 cx_Freeze/windist.py 做一个小的改动来解决这个问题。在 add_config() 的第 61 行,我改变了:

    msilib.add_data(self.db, "Shortcut",
            [("S_APP_%s" % index, executable.shortcutDir,
                    executable.shortcutName, "TARGETDIR",
                    "[TARGETDIR]%s" % baseName, None, None, None,
                    None, None, None, None)])
    

    msilib.add_data(self.db, "Shortcut",
            [("S_APP_%s" % index, executable.shortcutDir,
                    executable.shortcutName, "TARGETDIR",
                    "[TARGETDIR]%s" % baseName, None, None, None,
                    None, None, None, "TARGETDIR")]) # <--- Working directory.
    

    谢谢大家。

    【讨论】:

      【解决方案2】:

      the answer to another question 中找到了解决方案。 本质上,需要设置快捷表数据。下面shortcut_table 中的最后一个'TARGETDIR' 将工作目录设置为安装目录。

      ---从上面提到的答案中复制---

      from cx_Freeze import *
      
      # http://msdn.microsoft.com/en-us/library/windows/desktop/aa371847(v=vs.85).aspx
      shortcut_table = [
          ("DesktopShortcut",        # Shortcut
           "DesktopFolder",          # Directory_
           "DTI Playlist",           # Name
           "TARGETDIR",              # Component_
           "[TARGETDIR]playlist.exe",# Target
           None,                     # Arguments
           None,                     # Description
           None,                     # Hotkey
           None,                     # Icon
           None,                     # IconIndex
           None,                     # ShowCmd
           'TARGETDIR'               # WkDir
           )
          ]
      
      # Now create the table dictionary
      msi_data = {"Shortcut": shortcut_table}
      
      # Change some default MSI options and specify the use of the above defined tables
      bdist_msi_options = {'data': msi_data}
      
      setup(
          options = {
              "bdist_msi": bdist_msi_options,
          },
          executables = [
              Executable(
                  "MyApp.py",
                  )
              ]
          ) 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-18
        • 2012-07-31
        • 1970-01-01
        • 2019-09-04
        相关资源
        最近更新 更多