[英]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.