How to set get path to run exe?

Alphaprotocol 1 Reputation point
2020-12-04T22:31:02.293+00:00

Im developing an app to run an exe file on button click, but how do I set the path to run the exe regardless of the drive its copied on or moved to.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,644 questions
{count} votes

2 answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points
    2020-12-07T04:29:53.793+00:00

    If the program you want to run is in the same folder as the currently running
    program - e.g. ...\bin\Debug - then it should start if you just use the
    program filename:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Process.Start("setup.exe")
    End Sub
    
    • Wayne
    0 comments No comments

  2. WayneAKing 4,921 Reputation points
    2020-12-07T09:13:08.56+00:00

    A more robust method, that should work regardless of how the user starts your
    program. i.e. - Should work even if the user starts your program from some
    directory other than the one which holds the exe.

    Dim MyPath As String = Application.ExecutablePath
    MyPath = MyPath.Remove(MyPath.LastIndexOf("\") + 1) & "setup.exe"
    Process.Start(MyPath)
    
    • Wayne