c#中在自定义动作中静默安装的问题

本文关键字:安装 问题 静默 自定义 | 更新日期: 2023-09-27 18:18:21

我想在c#编写的自定义操作中默默地安装一个名为Instacal的应用程序。在这个自定义操作中,我还安装了其他应用程序,这很好(它们不是默默地安装的!)。

当静默安装名为Instacal的应用程序启动时,没有任何东西被安装(我检查程序和功能)。在我的自定义动作中,我做了以下操作:

int ms = 0;
// execute InstaCal silently - it must be present on the user machine!
var fileName = Path.Combine(folder3rdParty, @"Instacal'InstaCal.msi");
Process installerProcess;
installerProcess = Process.Start(fileName, "/q");
while (installerProcess.HasExited == false)
{
     StreamWriter file = new StreamWriter("c:''test.txt", true);
     file.WriteLine("ms: " + ms);
     file.Close();
     Thread.Sleep(250);
     ms += 250;
}

我正在写入一个文件,只是为了测试安装大约需要多长时间。在while循环中大约需要3秒,之后不会安装任何东西。

但是如果我在一个小的控制台应用程序中使用完全相同的代码,那么应用程序Instacal就会默默地成功安装。此安装大约需要9秒才能完成。

那么,我在代码中做错了什么吗?我是否错过了一些重要的自定义动作?谢谢:)

c#中在自定义动作中静默安装的问题

我建议您将代码修改如下:

然后使用MSIEXEC命令来安装包,而不是直接调用MSI。

int ms = 0;
// execute InstaCal silently - it must be present on the user machine!
var fileName = Path.Combine(folder3rdParty, @"Instacal'InstaCal.msi");
Process installerProcess;
installerProcess = Process.Start("msiexec", string.Format("/i '{0}' /q", fileName));
while (installerProcess.HasExited == false)
{
     StreamWriter file = new StreamWriter("c:''test.txt", true);
     file.WriteLine("ms: " + ms);
     file.Close();
     Thread.Sleep(250);
     ms += 250;
}