Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall a previous Installed msi created through cx_freeze bdist_msi

I often use cx_freeze to package my python source with all the dependencies and subsequently create a msi installation package through the distutils bdist_msi extension

The only issues happens when I try to reinstall a newly created msi windows installer without uninstalling the previous version. The uninstaller keeps record of all the previously uninstalled version of the software and that blots registry and uninstaller information.

Is it possible to detect a previously installed version of my software and uninstall it automatically without installing a new version?

I am aware of NSIS, and how with its python bindings to create installers, the above issue I mentioned could easily be resolved through it. Unfortunately, at this moment, I am not looking anything beyond what Python provides i.e. distutils.

like image 394
Abhijit Avatar asked Dec 13 '12 19:12

Abhijit


2 Answers

In cx_Freeze, bdist_msi has an option upgrade-code, which the docs describe as:

define the upgrade code for the package that is created; this is used to force removal of any packages created with the same upgrade code prior to the installation of this one

To specify it, I think you'd have to pass it to the setup() call something like this:

options = {"bdist_msi": {"upgrade-code":"..."}}

(I always forget whether it should be - or _ in the option names to use them like this, so if that's wrong, try it as upgrade_code)

Microsoft say that the upgrade code should be a GUID (a randomly generated code).

like image 67
Thomas K Avatar answered Oct 22 '22 18:10

Thomas K


Thomas K's answer is close, but at least in my case, not exact. After some trial and error, I found that the GUID needs to be enclosed in curly brackets:

bdist_msi_options = {
    "upgrade_code": "{96a85bac-52af-4019-9e94-3afcc9e1ad0c}"
    }

and these options need to be passed in alongside the "build_exe" options (some online examples use other names for these arguments, but I found that only bdist_msi works):

setup(  # name, version, description, etc...
        options={"build_exe": build_exe_options, # defined elsewhere
                 "bdist_msi": bdist_msi_options},
        executables=[Executable("run.py",
                                base="win32GUI",
                                shortcutName="My Program name",
                                shortcutDir='ProgramMenuFolder')])

With this code, in my case, previous installers were correctly uninstalled and removed from the add/remove programs list.

like image 30
rdchambers Avatar answered Oct 22 '22 17:10

rdchambers