Executable Path in Application

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
In my remote desk top app,right now I launch the VPN that is included with the app like this

VB.NET:
' declare a variable to access the Process class and instantiate the variable
Dim proc As New Process
' declare a variable to hold the path as a string
Dim path As String = "../../VPN/vpnsetup.exe"
' start the process
proc = Process.Start(path)
' wait for the process to finish before continuing on
proc.WaitForExit()

what I would like to do is launch the executable using 2.0 coding. I tried

VB.NET:
 ' declare a variable to access the Process class and instantiate the variable
Dim proc As New Process
' declare a variable to hold the path as a string
Dim path As String = Application.StartupPath("VPN/vpnsetup.exe")
' start the process
proc = Process.Start(path)
' wait for the process to finish before continuing on
proc.WaitForExit()

but this did not work. The .exe file is set to copy out when deployed and it works in the first version, what am I doing wrong in the second?

Suggestions
CoachBarker
 
As JohnH indicates, Application.StartupPath is not used in that way. It simply returns a string containing a folder path. If you want to extend that path then you simply join that string to another. The best way to do that is with the Path.Combine method.
 
OK, in the app I read a text file by doing this

VB.NET:
' get the path for the LocalPath 
Dim lp As String = IO.File.ReadAllText("TextFiles\LocalPath.txt")
txtLocalPath.Text = lp

instead of creating a function to use a stream reader to get the path to the text file, and then calling that function whenever I need to read the text file, right?

VB.NET:
Public Function getDBConnectionString() As String
        ' error handling
        Try
            ' hard coded config file
            Dim sr As New StreamReader("../../TextFiles/LocalPath.txt")
            ' everytime you get a line you should decrypt it
            Dim line As String
            ' first get the database to use
            line = sr.ReadLine
            Dim DatabaseType As String = Mid(line, 11)
            Do
                line = sr.ReadLine
                ' then get the connection string
                If InStr(line, DatabaseType) <> 0 Then
                    line = Mid(line, Len(DatabaseType) + 3)
                    Return line
                End If
            Loop Until line Is Nothing
            ' close the file
            sr.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return Nothing
    End Function

So I want to be able to access the exe file that is included in the app without using the 1.1 method of "../../VPN/vpnsetup.exe" if my SolutionExplorer looks like this

SolutionExplorer.JPG

What happens is that the app checks to see if the VPN is installed on the local computer and if not launches the VPN setup file.

Does that make sense?

Thanks
CoachBarker
 
Back
Top