在C#中的自定义操作中进行静默安装的问题

时间:2014-08-18 09:39:48

标签: c# custom-action silent-installer

我想在用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秒钟才能完成。

那么,我在代码中做错了吗?我错过了有关自定义操作的重要信息吗? thx:)

1 个答案:

答案 0 :(得分:1)

我建议您将代码更改为以下内容:

然后使用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;
}