使用 C# 静默卸载 InstallShield Installscript MSI 程序 [英] Uninstalling an InstallShield Installscript MSI program using C# silently

查看:54
本文介绍了使用 C# 静默卸载 InstallShield Installscript MSI 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将非常特定于 InstallShield,所以我怀疑以前有人处理过这个问题,但我写了一个批处理文件来卸载我们产品的先前版本,但它不起作用.(我们总是在安装/升级之前卸载以前的版本,因为 InstallShield 中的升级似乎不起作用).卸载 Installscript MSI 项目与典型的卸载非常不同,因为您需要记录"卸载并将结果存储在文件中,即:

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"

这会将卸载映像存储在 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"

所以我对我们产品的所有先前版本都这样做,然后编写了一个批处理脚本(产品代码为 {7F2A0A82-BB08-4062-85F8-F21BFC3F3708} 来执行如下所示的卸载:

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...

问题是它不起作用.如果我从提升的 CMD 窗口执行卸载,它工作正常:

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"

但是当我执行批处理脚本时,它似乎只是通过卸载而没有做任何事情.所以我想我会尝试编写一个简单的 C# 程序来做到这一点,但这也不起作用:

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();
        }
    }

我试过调试这个并确认当前目录是正确的(使用Directory.GetCurrentDirectory()),但我得到这个错误:

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}

推荐答案

正如 Gravity 指出的,问题是/和 f1 之间的空格.它在剪辑过程中以某种方式添加了 &粘贴.

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

这篇关于使用 C# 静默卸载 InstallShield Installscript MSI 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆