Shell function

changobutt

Newcomer
Joined
Dec 11, 2003
Messages
23
I'm trying to run an .msi file using the Shell function, but I guess it doesn't 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, don't use Shell... that's one of the old VB6 functions. Use
Visual Basic:
System.Diagnostics.Process.Start("C:\mySetup.msi")

But, if the error says the file is not found, then chances are you're
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!).

Visual Basic:
Dim p As System.Diagnostics.Process

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