Announcement

Collapse
No announcement yet.

Uninstalling previous version

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Uninstalling previous version

    Hi All,

    How do I uninstall previous versions of my product before installing new ones?

    Thanks,

    Alberto

  • #2
    You should know where you are storing the info about your application.

    Ulrich

    Comment


    • #3
      Hi Ulrich,

      Please provide us detailed step on how to support uninstallation before installation because the tool we were using (InstallAware) did everything automatically and we are completely new to this topic.

      Shall we add an action in the OnPreInstall group? What action shall we add?

      Thanks,

      Alberto

      Comment


      • #4
        Originally posted by devdept View Post
        Hi Ulrich,

        Please provide us detailed step on how to support uninstallation before installation because the tool we were using (InstallAware) did everything automatically and we are completely new to this topic.
        Here is some sample code to look at. Edit as required.

        Code:
        [COLOR="#008000"]-- unique registry key is set in the Uninstall Settings[/COLOR]
        uninstall_key [COLOR="#FF0000"]=[/COLOR] Registry[COLOR="#FF0000"].[/COLOR]GetValue(HKEY_LOCAL_MACHINE[COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"SOFTWARE[COLOR="#800080"]\\[/COLOR]Microsoft[COLOR="#800080"]\\[/COLOR]Windows[COLOR="#800080"]\\[/COLOR]CurrentVersion[COLOR="#800080"]\\[/COLOR]Uninstall[COLOR="#800080"]\\[/COLOR]uniqueregkey"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"UninstallString"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]false[/COLOR]);
        
        [COLOR="#008000"]-- extract uninstaller name and path from the key[/COLOR]
        [COLOR="#008000"]-- example: "C:\folder\uninstall.exe" "/U:C:\folder\Uninstall.xml"[/COLOR]
        sMyUninstallInfo [COLOR="#FF0000"]=[/COLOR] [COLOR="#FF0000"]{}[/COLOR];
        [COLOR="#0000FF"]local[/COLOR] i [COLOR="#FF0000"]=[/COLOR] [COLOR="#000000"]1[/COLOR];
        [COLOR="#0000FF"]for[/COLOR] s [COLOR="#0000FF"]in[/COLOR] [COLOR="#0000FF"]string.gfind[/COLOR](uninstall_key[COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]'"([^%"]+)"'[/COLOR]) [COLOR="#0000FF"]do[/COLOR]
          sMyUninstallInfo[COLOR="#FF0000"][[/COLOR]i[COLOR="#FF0000"]][/COLOR] [COLOR="#FF0000"]=[/COLOR] s;
          i [COLOR="#FF0000"]=[/COLOR] i + [COLOR="#000000"]1[/COLOR];
        [COLOR="#0000FF"]end[/COLOR]
        uninstaller [COLOR="#FF0000"]=[/COLOR] sMyUninstallInfo[COLOR="#FF0000"][[/COLOR][COLOR="#000000"]1[/COLOR][COLOR="#FF0000"]][/COLOR];
        parameters [COLOR="#FF0000"]=[/COLOR] sMyUninstallInfo[COLOR="#FF0000"][[/COLOR][COLOR="#000000"]2[/COLOR][COLOR="#FF0000"]][/COLOR];
        
        StatusDlg[COLOR="#FF0000"].[/COLOR]Show();
        StatusDlg[COLOR="#FF0000"].[/COLOR]SetMessage([COLOR="#800080"]"Please wait..."[/COLOR]);
        StatusDlg[COLOR="#FF0000"].[/COLOR]ShowProgressMeter([COLOR="#0000FF"]false[/COLOR]);
        
        [COLOR="#008000"]-- perform the uninstall, silently[/COLOR]
        File[COLOR="#FF0000"].[/COLOR]Run(uninstaller[COLOR="#FF0000"],[/COLOR] parameters [COLOR="#FF0000"]..[/COLOR] [COLOR="#800080"]" /S"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]""[/COLOR][COLOR="#FF0000"],[/COLOR] SW_HIDE[COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]true[/COLOR]);
        
        [COLOR="#008000"]-- now wait for the uninstaller to be deleted in the background before deploying the new version[/COLOR]
        [COLOR="#008000"]-- remove quotes from the filename, if any[/COLOR]
        uninstaller [COLOR="#FF0000"]=[/COLOR] u_path;
        [COLOR="#0000FF"]if[/COLOR] (String[COLOR="#FF0000"].[/COLOR]Left(uninstaller[COLOR="#FF0000"],[/COLOR] [COLOR="#000000"]1[/COLOR]) [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
          uninstaller [COLOR="#FF0000"]=[/COLOR] String[COLOR="#FF0000"].[/COLOR]Mid(uninstaller[COLOR="#FF0000"],[/COLOR] [COLOR="#000000"]2[/COLOR][COLOR="#FF0000"],[/COLOR] -[COLOR="#000000"]1[/COLOR]);
        [COLOR="#0000FF"]end[/COLOR]
        [COLOR="#0000FF"]if[/COLOR] (String[COLOR="#FF0000"].[/COLOR]Right(uninstaller[COLOR="#FF0000"],[/COLOR] [COLOR="#000000"]1[/COLOR]) [COLOR="#FF0000"]==[/COLOR] [COLOR="#800080"]"[COLOR="#800080"]\"[/COLOR]"[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
          uninstaller [COLOR="#FF0000"]=[/COLOR] String[COLOR="#FF0000"].[/COLOR]Mid(uninstaller[COLOR="#FF0000"],[/COLOR] [COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] String[COLOR="#FF0000"].[/COLOR]Length(uninstaller)-[COLOR="#000000"]1[/COLOR]);
        [COLOR="#0000FF"]end[/COLOR]
        
        [COLOR="#0000FF"]while[/COLOR] File[COLOR="#FF0000"].[/COLOR]DoesExist(uninstaller) [COLOR="#0000FF"]do[/COLOR]
          SetupData[COLOR="#FF0000"].[/COLOR]WriteToLogFile([COLOR="#800080"]"Waiting one second...[COLOR="#800080"]\r[/COLOR][COLOR="#800080"]\n[/COLOR]"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]true[/COLOR]);
           Application[COLOR="#FF0000"].[/COLOR]Sleep([COLOR="#000000"]1000[/COLOR]);
        [COLOR="#0000FF"]end[/COLOR]
        StatusDlg[COLOR="#FF0000"].[/COLOR]Hide();
        Shall we add an action in the OnPreInstall group? What action shall we add?
        Yes, the uninstall procedure should best be performed in the On Pre Install script, which is fired after all of the Before Installing screens were displayed.

        Ulrich
        Last edited by Ulrich; 11-30-2010, 06:03 AM. Reason: Sample used some Lua 5.1

        Comment


        • #5
          Hi Ulrich,

          I understand the code you provided (thanks), but it actually fails on machine where the product is not installed yet. Probably the best way is to skip everything if the:

          Code:
          uninstall_key = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\uniqueregkey", "UninstallString", false);
          doesn't find the 'uniqueregkey'.

          How can we code it?

          Thanks,

          Alberto

          Comment


          • #6
            Hello,

            you have to put some effort in learning the Lua language and studying the documentation. If Registry.GetValue() fails, an empty string is returned. Here is how you should perform the test:

            Code:
            [COLOR="#008000"]-- unique registry key is set in the Uninstall Settings[/COLOR]
            uninstall_key [COLOR="#FF0000"]=[/COLOR] Registry[COLOR="#FF0000"].[/COLOR]GetValue(HKEY_LOCAL_MACHINE[COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"SOFTWARE[COLOR="#800080"]\\[/COLOR]Microsoft[COLOR="#800080"]\\[/COLOR]Windows[COLOR="#800080"]\\[/COLOR]CurrentVersion[COLOR="#800080"]\\[/COLOR]Uninstall[COLOR="#800080"]\\[/COLOR]uniqueregkey"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"UninstallString"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]false[/COLOR]);
            [COLOR="#0000FF"]if[/COLOR] (uninstall_key [COLOR="#FF0000"]~=[/COLOR] [COLOR="#800080"]""[/COLOR]) [COLOR="#0000FF"]then[/COLOR]
              [COLOR="#008000"]-- extract uninstaller name and path from the key[/COLOR]
              [COLOR="#008000"]-- example: "C:\folder\uninstall.exe" "/U:C:\folder\Uninstall.xml"[/COLOR]
            
              [COLOR="#008000"]-- code suppressed ...[/COLOR]
            
              [COLOR="#0000FF"]while[/COLOR] File[COLOR="#FF0000"].[/COLOR]DoesExist(uninstaller) [COLOR="#0000FF"]do[/COLOR]
                SetupData[COLOR="#FF0000"].[/COLOR]WriteToLogFile([COLOR="#800080"]"Waiting one second...[COLOR="#800080"]\r[/COLOR][COLOR="#800080"]\n[/COLOR]"[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#0000FF"]true[/COLOR]);
                 Application[COLOR="#FF0000"].[/COLOR]Sleep([COLOR="#000000"]1000[/COLOR]);
              [COLOR="#0000FF"]end[/COLOR]
              StatusDlg[COLOR="#FF0000"].[/COLOR]Hide();
            [COLOR="#0000FF"]end[/COLOR]
            Ulrich

            Comment


            • #7
              Thanks Ulrich,

              Now it works but it happens everything so quickly that we cannot understand if everything is done as expected. Two more questions arise:

              1) Is it possible to debug this code without actually installing the product?
              2) Can I stop here and there displaying a MessageBox() to understand if the installer code is executed correctly?

              Thanks,

              Alberto

              Comment


              • #8
                1) Is it possible to debug this code without actually installing the product?
                You can build an empty installer and place this code in the On Startup event, exiting the installer afterwards.

                2) Can I stop here and there displaying a MessageBox() to understand if the installer code is executed correctly?
                There are several aids available for debugging your scripts. You find them documented in the help file. Just a few examples:
                • Debug.ShowWindow()
                • Debug.SetTraceMode()
                • Debug.Print()
                • Dialog.Message()
                • SetupData.WriteToLogFile()


                Ulrich

                Comment


                • #9
                  Hi Ulrich,

                  One last thing (hopefully). How I cannot use the variable 'uniqueRegKey'? The code below does not work...

                  Code:
                  uniqueRegKey = "MyProduct 4.0 Beta"
                  
                  -- unique registry key is set in the Uninstall Settings
                  uninstall_key = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"..uniqueRegKey, "UninstallString", false);
                  Thanks,

                  Alberto

                  Comment

                  Working...
                  X