Installer fails when launched using Process.Start() but works when double-clicked
I'm having issues with System.Diagnostics.Process.S开发者_开发问答tart()
.
When I am launching a third-party installer (MSI package wrapped in an executable), it installs without problems when it is launched by double-clicking the exe or invoked from the command line.
However, when I'm launching it from within an application by using Process.Start()
, the installer fails with error code 5 = access denied. The logs say that it fails because it cannot restore some Registry settings.
Does anyone know the difference (security-wise) between double-clicking the exe and launching a process from within the application? User runs as administrator.
Example code:
var info = new ProcessStartInfo();
info.FileName = @"C:\MyFolder\setup.exe";
info.UseShellExecute = false; // I have tried both true and false here
Process p = Process.Start(info);
p.WaitForExit();
if (p.ExitCode != 0)
{
// Do something...
}
UPDATE:
I put the code above in a small console application and it worked. Obviously something fishy was going on in the main app...
It turned out I had forgotten to close some Registry keys. The installer failed since it tried to access those same keys. As soon as I closed the keys properly, the code worked.
Sorry folks. Shame on me.
So that might not work the way you'd expect it to anyway; I'm assuming you're going for an unattended installation. Try something like this:
Process installer = new Process()
installer.StartInfo.FileName = @"C:\MyFolder\Setup.exe";
installer.StartInfo.Arguments = " /s /v\" /qn\"";
installer.Start()
installer.WaitForExit();
if ( installer.ExitCode != 0 )
{
//do something
}
The argument tells the installer exe to run silently ( /s ) and to pass arguments down to the MSI ( /v ). The /qn is the Windows Installer argument to run the installer silently, which should require no user interaction and should allow the installer to run properly.
Did you try setting info.Verb = "runas"?
This will make the application/installer run as administrator. It is the same thing as right clicking an icon and telling it to run as administrator
精彩评论