0

I feel really silly having to ask this question as I know I should not be having so much trouble with this simple task....but I am trying to launch my .msi when a user pushes a button of a form. I am certain this is a one liner but I cannot for the life of me figure this out. I have the .MSI file on my desktop so I want the button to also be able to have the user select where the msi file is. If anyone could help me that would be grand...

user1270384
  • 711
  • 7
  • 24
  • 53
Jimmy
  • 941
  • 2
  • 8
  • 27
  • To see which commands you need to execute, take a look at http://technet.microsoft.com/en-us/library/cc759262(v=ws.10).aspx – Espen Burud Apr 17 '12 at 20:54
  • See this article https://stackoverflow.com/questions/258416/shellexecute-equivalent-in-net which basically shows the C# way of calling ShellExecute. – Joseph Willcoxson Apr 17 '12 at 20:53

2 Answers2

10

Look at Process.Start.

Process.Start("path to msi");

To get the path to the file, you can use the FileDialog class (assuming winforms).

OpenFileDialog openFileDialog1 = new OpenFileDialog();

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
   Process.Start(openFileDialog1.FileName);
}
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Okay that launches the MSI :-), now what about being able to have the user select the .msi location rather than hard coding it in? Also thank you for the crazy fast response! – Jimmy Apr 17 '12 at 20:55
  • @Jimmy - Look at [the answer](http://stackoverflow.com/users/1070216/jmyster) from @Jmyster, using the `FileDialog`. – Oded Apr 17 '12 at 20:56
1

Look at using this to get the file:

FileDialog dialog = new FileDialog();
Jmyster
  • 965
  • 2
  • 9
  • 27