2

I have a task to develop an update agent that launches an msi file after downloading it, the installation has to be invisible to the user.

But i have a problem with launching it with no UI. I tried using /q and /qn but it doesn't work, it only works with UI options.

internal static class MSI_runner
{
    public static bool RunInstallMSI(string sMSIPath)
    {
        try
        {
            Console.WriteLine("begin");
            //Starting to install application
            Process process = new Process();
            process.StartInfo.FileName = "msiexec.exe";
            process.StartInfo.Arguments = string.Format(" /q  /i \"{0}\" REINSTALLMODE=amus ", sMSIPath);
            Console.WriteLine("start");

            process.Start();
            process.WaitForExit();
            Console.WriteLine("end");

            return true;
        }
        catch
        {
            // "There was a problem installing the application!
            return false;  //Return False if process ended unsuccessfully
        }
    }
}
DIF
  • 2,470
  • 6
  • 35
  • 49

2 Answers2

0

The most likely reason is that the install requires elevation, so there are a few things that this affects, but there are some guesses here because your "but it doesn't work" isn't very specific.

  1. When you run it in UI mode it probably asks for elevation. An administrator would just get an elevation prompt, a limited user would be asked to enter admin credentials. Either way, it runs elevated. When you run it silently the elevation prompt is not shown (silent means silent) and therefore it fails silently too because it requires elevated privileges.

  2. Your code almost certainly defaults to ProcessStartInfo.UseShellExecute=true, so any credentials of the process will not be used to launch the MSI. In situations where the MSI needs elevation and you want to install it silently you must give your exe a manifest for elevation (so it prompts) or runs elevated some other way. You also need UseShellExecute to be false so that the launch is a CreateProcess type of launch where the process privileges are inherited into the process you launch. In addition, there's also no real need to launch anything and get into this type of issue. If your process is elevated then just call MsiInstallProduct passing the path to the MSI and the command line. Then you know that the install runs with your privileges.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370315(v=vs.85).aspx

Assuming that your code is working, and as an aside, it's not clear what type of upgrade you are expecting. There's no mention of whether your MSI has a new ProductCode, ProductVersion etc. The normal method of applying a small update by reinstalling a new MSI with REINSTALLMODE is here:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa367575(v=vs.85).aspx

and REINSTALLMODE should be vomus.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
-1

try cactch (Exception ex) and see what ex.message is. check here for msiexec params : http://www.advancedinstaller.com/user-guide/msiexec.html

Alex Banu
  • 28
  • 3