Search code examples
c#windows-installerinstallscript-msi

Uninstalling an InstallShield Installscript MSI program using C# silently


This is going to be very specific to InstallShield, so I doubt anyone has dealt with this before, but I wrote a batch file to uninstall prior versions of our product and it doesn't work. (We always uninstall prior versions prior to an install/upgrade since the Upgrades in InstallShield don't seem to work). Uninstalling Installscript MSI projects is very different from typical uninstalls in that you need to "record" an uninstall and store the results in a file i.e.:

setup.exe /x /r /f1"C:\temp\UNINST.ISS"

This stores the uninstall image in c:\temp\UNINST.ISS and then you need to pass that to the uninstaller to get the product to uninstall:

setup.exe /s /f1"UNINST.ISS"

So I did this for all prior versions of our product and then wrote a batch script (with the product code being {7F2A0A82-BB08-4062-85F8-F21BFC3F3708} to do the uninstalls that looks like this:

echo Uninstalling 5.3.0
pause
if exist "C:\Program Files (x86)\InstallShield Installation Information\ {7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe" (
    del /q "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe"
    copy /y "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe" "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe"
    cls
    echo Uninstalling 5.3.0
    "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe" /s /f1".\Uninstall response files\5.3.0\UNINST-5.3.0.ISS"
    :wait1
        timeout /t 3 /NOBREAK > nul
        tasklist | find /i "Setup-5.3.0.exe" >nul 2>nul
        if not errorlevel 1 goto wait1
)

echo Uninstalling 5.3.1...

The problem is that it doesn't work. If I execute the uninstall from an elevated CMD window it works fine:

"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe" /s /f1".\Uninstall response files\5.3.0\UNINST-5.3.0.ISS"

But when I execute the batch script it just seems to pass right by the uninstall and not do anything. SO I thought I'd try to write a simple C# program to do this but that's not working either:

Console.Clear();
Console.WriteLine("Uninstalling 5.3.0");
if (File.Exists(@"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe"))
    {
        File.Copy(@"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe", @"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe", true);

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = @"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe";
        Directory.SetCurrentDirectory(@"..\..\..\");
        startInfo.Arguments = "/s / f1\".\\Uninstall response files\\5.3.0\\UNINST-5.3.0.ISS\"";
        startInfo.UseShellExecute = false;
        startInfo.WindowStyle = ProcessWindowStyle.Normal;
        using (Process process = new Process())
        {
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
        }
    }

I've tried debugging this and confirmed that the current directory is correct (using Directory.GetCurrentDirectory()), but I get this error:

process.StandardError' threw an exception of type 'System.InvalidOperationException'    System.IO.StreamReader {System.InvalidOperationException}

Solution

  • As Gravity pointed out the problem was a space between the / and the f1. It got added somehow during the cut & paste.