Uninstalling an InstallShield Installscript MSI program using C# silently
Asked Answered
G

2

0

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}
Greensboro answered 15/8, 2018 at 19:34 Comment(2)
This part: "/s / f1\".\\Unin.... Did you intend for a space between the / and the f1 where it isn't in your manually run command-line example?Automatize
Nope - it got in there copying and pasting from batch to c# for some reason. There was another space added that I caught but this one slipped by. Thanks - it seems to work now - great eye seeing that!Greensboro
G
0

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

Greensboro answered 16/8, 2018 at 15:14 Comment(0)
B
1

There are some further instructions towards the bottom of this PDF: https://resources.flexera.com/web/pdf/archive/silent_installs.pdf

setup.exe /s /f1"C:\sample\uninstall.iss" /f2"C:\sample\uninstall.log"

Did you try it manually with full paths for both the /f1 and /f2 parameters?

I am actively trying to forget how to write batch files, but I think you can get the folder where the batch file is running from like this:

set here=%~dp0
cd %here%

Could changing the setup.exe file name cause problems? Maybe you can try without changing the name of the setup.exe and see if that completes?

Could passing the command to cmd.exe via the /c parameter be an idea? ("carries out the command specified by the string and then terminates"):

cmd.exe /c "%here%\setup.exe /s /f1"C:\sample\uninstall.iss" /f2"C:\sample\uninstall.log""

Maybe try adding the /SMS switch to ensure that the setup.exe does not exit prematurely before the actual uninstall is complete. As rumor has it this /SMS switch is not needed for late-generation Installshield setup.exe, but it is needed for older versions.

Bedeck answered 16/8, 2018 at 5:7 Comment(0)
G
0

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

Greensboro answered 16/8, 2018 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.