Launching MSIExec.exe From C#

I ran into a problem with trying to spawn off a process to launch an MSIExec.exe command from C#.  I wanted to launch the process and then wait for it to finish before proceeding; however,  it was always returned immediately before the install or uninstall was really finished.  I confirmed this behavior with this blog entry:

The author suggests "start /wait" which works from the command line or a batch file.  I did verify it works launching a batch file or two from C#, but I preferred to keep in C# as much as possible.  Also, I was trying to accomplish a silent background process running the MSIExec commands.  However, C# can’t just start a process calling "start," which is an internal command to the Command Prompt I guess.

Someone reminded me on a message board that you can start a process using CMD.exe, calling "start" like this:

ProcessStartInfo startInfo = new ProcessStartInfo(
    string.Format("/c start /MIN /wait msiexec.exe /x {0} /quiet", guid));
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

Process process = Process.Start(startInfo);

It works like a charm.  I don’t think you even need the "/MIN" flag for "start" anyway.


Tyler Collier
Thanks for this. Great idea. Worked for me.
You could use process.WaitForExit() isn't it?