简体   繁体   中英

How to run msi installer in cmd as admin using C#

I have an msi installer that I need to install it silently from the C#

Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.WorkingDirectory = @"C:\temp\";
process.StartInfo.Arguments = "msiexec /quiet /i Setup.msi ADDLOCAL=test";
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit(60000);

noting that the cmd command is working fine if I manually run it from the cmd as admin

when I run it I just get the cmd screen in admin mode but the command does not executing

as V2Solutions - MS Team mentioned , the solution is to change the following

process.StartInfo.FileName = "msiexe.exe" 

and the code will be

Process process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.WorkingDirectory = @"C:\temp\";
process.StartInfo.Arguments = " /quiet /i Setup.msi ADDLOCAL=test";
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit(60000);

this works for me :)

This is also going to help you:

Process process = new Process();
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = string.Format("/qn /i \"{0}\" ALLUSERS=1", @"somepath\msiname.msi");
process.Start();
process.WaitForExit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM