Diemauerdk
Diemauerdk

Reputation: 5958

Problems making a silent install within a Cusom Action in C#

I want to silently install an application named Instacal within my Custom Action written in C#. In this custom action i am also installing other applications and this works fine(they are not silently installed!).

When the silent installation of the application named Instacal is started, nothing is ever installed(i check Programs and Features). In my Custom Action I do the following:

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;
}

I am writing to a file just to test how long time the installaltion approximately takes. It takes about 3 seconds in the while loop and afterwards nothing is installed.

But if i use the exactly same code in a small console application then the application Instacal is succesfully installed silently. This installation take about 9 seconds to complete.

So, am i doing something wrong in the code? Am i missing something important regarding custom actions? thx :)

Upvotes: 0

Views: 248

Answers (1)

Johan J v Rensburg
Johan J v Rensburg

Reputation: 322

I would suggest that you change your code to the following:

This then uses the MSIEXEC command to install your package instead of calling the MSI directly.

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;
}

Upvotes: 1

Related Questions