Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 326
Ateeq Avatar asked Sep 09 '14 06:09

Ateeq


People also ask

How do I run an MSI with administrator rights?

Run MSI as administrator from Command Prompt To do so, type CMD in Start menu or Start screen search box, and then simultaneously press Ctrl+Shift+Enter keys.

How do I run installer as administrator?

If a program requires Administrator privileges to perform certain functions, you need to run the program as Administrator. To run a program as Administrator in Windows 10, right-click the icon in your Start menu and select Run as administrator.


2 Answers

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 :)

like image 130
Ateeq Avatar answered Sep 17 '22 11:09

Ateeq


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();
like image 33
cracker Avatar answered Sep 18 '22 11:09

cracker