Reputation: 18295
In VB.net, how can you programmatically launch a .exe file? Is there a way to check if the file is there?
I know there is some way to check using System.IO, but I have no idea. However, I have not even the slightest clue as to how to launch that .exe if it is there, so thanks for the help!
Upvotes: 2
Views: 297
Reputation: 3386
You can use System.Diagnostics.Process to execute an .EXE, and can even capture the output if it is a console / command-line application. You would have something like this (but bear in mind this is simplified quite a bit!):
dim process as System.Diagnostics.Process
process.StartInfo.FileName = "program.exe" ' You need to be smarter here!
process.StartInfo.Arguments = "whatever command line options you need"
process.Start()
To check if the program is still running you call
process.HasExited()
If you want to capture the output you need to set StartInfo.RedirectStandardOutput to True.
Upvotes: 1
Reputation: 6453
Use System.IO.File.Exists and System.Diagnostics.Process.Start.
Dim someExe As String = "MyAppsPath\some.exe"
Dim fullPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), someExe)
If File.Exists(fullPath) Then 'Checks for the existence of the file
Process.Start(fullPath) 'Executes it
End If
Upvotes: 2
Reputation: 13498
Check out the System.Diagnostics.Process class. There's a perfect code snippet on the MSDN page, so I won't duplicate it here.
The neat thing about Process is that you can actually launch a file (say, an HTML file) and it will open using the user's default browser. Many common programs accept command-line parameters as well - many browsers accept a URL as a command-line parameter so you can open a specific URL.
Upvotes: 2
Reputation: 211
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
openFileDialog od = new OpenFileDialog(); string path = od.ToString() System.Diagnostics.Process.Start(path)
Upvotes: 1