Shell function

changobutt

Member
Joined
Dec 11, 2003
Messages
23
Im trying to run an .msi file using the Shell function, but I guess it doesnt like it.

Shell("C:\mySetup.msi", AppWinStyle.NormalFocus, True)

It gives me the following error:

------------------------------------
An unhandled exception of type System.IO.FileNotFoundException occurred in microsoft.visualbasic.dll

Additional information: File not found.
------------------------------------


Is there a way I can execute an .msi file with code?

Thanks!
 
Eek, dont use Shell... thats one of the old VB6 functions. Use
Code:
System.Diagnostics.Process.Start("C:\mySetup.msi")

But, if the error says the file is not found, then chances are youre
passing an incorrect filename.
 
Awesome! Thanks a bunch!

Now, is there a way to wait for the process to finish (for the .msi installation to be closed) before giving the control back and executing the next line of code?

Thanks again!
 
Yeah. The static Process.Start() method returns a Process object,
which has a WaitForExit() method (how handy!).

Code:
Dim p As System.Diagnostics.Process

p = System.Diagnostics.Process.Start("C:\mySetup.msi")
p.WaitForExit()
 
Back
Top