使用C#静默卸载InstallShield Installscript MSI程序

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

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

这将卸载映像存储在c:\ temp \ UNINST.ISS中,然后您需要将其传递给卸载程序以获取要卸载的产品:

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

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

 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窗口执行卸载它工作正常:

 "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#程序来执行此操作,但这也不起作用:

 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() ),但是我收到此错误:

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

本PDF的底部还有一些进一步的说明: https : //resources.flexera.com/web/pdf/archive/silent_installs.pdf

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

您是否手动尝试使用/f1/f2参数的完整路径?

我正在积极地试图忘记如何编写批处理文件,但我认为你可以得到运行批处理文件的文件夹,如下所示:

 set here=%~dp0 cd %here% 

更改setup.exe文件名会导致问题吗? 也许你可以尝试不改变setup.exe的名称,看看是否完成?

可以通过/ c参数将命令传递给cmd.exe吗? (“ 执行字符串指定的命令,然后终止 ”):

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

也许尝试添加/ SMS开关以确保在实际卸载完成之前setup.exe不会过早退出。 据传闻,后期生成的Installshield setup.exe不需要这个/ SMS开关,但旧版本需要它。

正如Gravity所指出的那样,问题是/和f1之间的空间。 它在切割和粘贴过程中以某种方式添加。