Andie Andie - 29 days ago 13
C# Question

C# How can I run an msi installation package as a different user

I need to be able to install crystal reports on end user computers, but the network security wont allow it on a normal user login, so it has to be 'run as a different user' to install on each desktop.

I am trying to create a small application which will allow any user to install crystal reports.. so far I have:

Process p = new Process();
p.StartInfo.FileName = @"C:\cabs\CRRuntime_32bit_13_0_5.msi";
p.StartInfo.Arguments = "/i \"C:\\Application.msi\"/qn";
p.StartInfo.UserName = uname;
p.StartInfo.Password = pword;
p.StartInfo.Domain = domain;
p.StartInfo.UseShellExecute = false;


try
{
p.Start();
}
catch(Exception er)
{
MessageBox.Show(er.Message);
}


When I try to run this code, I see the message "The specified executable is not a valid application for this OS platform"

did I miss something out?

CHeers

Answer

MSI is not a executable file in windows. You should call msiexec with you msi file as parameter

Process p = new Process();
p.StartInfo.FileName =   @"C:\Windows\System32\msiexec.exe";
p.StartInfo.Arguments = @"C:\cabs\CRRuntime_32bit_13_0_5.msi";
p.StartInfo.UserName = uname;
p.StartInfo.Password = pword;
p.StartInfo.Domain = domain;
p.StartInfo.UseShellExecute = false;