VB.net lauching a program from sub folder

5k views Asked by At

So I need to lauch an external application from the sub folder of the program. The application will be deployed with the program but may be in different locations so I can't hardcode it to "c:\folder\example.exe"

When I run this I get an error that file cannot be found although I have the folder and file in \bin\debug.

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    System.Diagnostics.Process.Start("\app\ds104.exe")
End Sub

Even when the application is in the root folder which will not be ideal I get the same error.

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    System.Diagnostics.Process.Start("ds104.exe")
End Sub

Thank you for taking a look.

1

There are 1 answers

1
Alex Essilfie On BEST ANSWER

The Process.Start() method takes a full path as the argument.

You can get the path your application is running from by using the My.Application.Info.DirectoryPath property. You then join it with the location of the application you want to run and then call the Process.Start() method.

Example:

Imports System.Diagnostics

...

Private Sub StartApplication()
    Process.Start(My.Application.Info.DirectoryPath & "\Path\To\App.exe")
End Sub