Your going to want to make a folder in your projects Debug folder that contains the exe files you want to have listed in your combobox to run for now if your projects exe is not on the thumb drive where the subfolder with exe files are located. Then later you can copy your projects exe file and the folder containing the exe`s to the thumb drive.
You need to have some sort of a fixed way to find the exe files from your app.
For example my test project is called "Run Exe from subfolder on thumb drive.exe" and is located directly on my thumb drive. I also made a folder on the thumb drive called "Apps" that i put a few exe files in that i want to run from my app. So the paths look like this.
My test project:
E:\Run Exe from subfolder on thumb drive.exe
The exe paths for the programs i want to run:
E:\Apps\Color Picker.exe
E:\Apps\QuickVal.exe
My test project is a simple form with 1 ComboBox and 1 Button on it and uses the code below. When it is run it will list all the exe files in the Apps folder. Then when i select a program in the combobox and press the button it will run that program from the Apps folder.
- Public Class Form1
-
'Adds "Apps" to the directory that this apps exe file was started from
-
Private AppsPath As String = IO.Path.Combine(Application.StartupPath, "Apps")
-
-
Private ExeFullPaths As New List(Of String) 'This will hold all the full pathnames to the exe files
-
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList 'make it so user cant type in the combobox
-
-
For Each fn As String In IO.Directory.GetFiles(AppsPath, "*.exe") 'iterate through all the exe files in the AppsPath directory
-
ExeFullPaths.Add(fn) 'add the full path to a list so you can start the exe file depending on the selected index of the combobox
-
ComboBox1.Items.Add(IO.Path.GetFileNameWithoutExtension(fn)) 'add just the filename to the combobox
-
Next
-
-
If ComboBox1.Items.Count > 0 Then ComboBox1.SelectedIndex = 0 'selects the first file if there was any files found and added to combobox
-
End Sub
-
-
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
-
If ComboBox1.SelectedIndex > -1 Then 'makes sure there is an item selected before trying to start one
-
Process.Start(ExeFullPaths(ComboBox1.SelectedIndex)) 'start the selected exe file
-
End If
-
End Sub
-
End Class
-