[英]Uninstalling an InstallShield Installscript MSI program using C# silently
这将非常特定于 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 之间的空格。 它是在剪切和粘贴过程中以某种方式添加的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.