tags:

views:

35

answers:

2

How would I open a program within Visual Basic 2010? (Like running "Application.txt" from "C:\" within a Visual Basic project.

    Public Class getfrom

        Dim getfrom As String
        Dim saveto As String
        Dim download As Boolean

        Function openRunt()
            Dim myProcess As New Process()
            Try

                myProcess.StartInfo.UseShellExecute = False
                myProcess.StartInfo.FileName = "C:\\Runt.exe"
                myProcess.StartInfo.CreateNoWindow = True
                myProcess.Start()
            Catch e As Exception
                ' do nothing.
            End Try
            Return False
        End Function

        Function setVariables()
            ' Download the file from..
            getfrom = "http://sourceforge.net/projects/iforsm/files/iForsm.exe"
            ' Download the file to..
            saveto = "C:\Runt.exe"
            ' Allow download..
            download = True

            Return False
        End Function

        Private Sub getfrom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            setVariables()
            If download = True Then
                My.Computer.Network.DownloadFile(getfrom, saveto)
                Dim fileExists As Boolean
                fileExists = My.Computer.FileSystem.FileExists("C:\Runt.exe")
                If fileExists = True Then
                    'System.Diagnostics.Process.Start("notepad.exe", "c:\Application.txt")
                    openRunt()
                End If
            Else
                End
            End If
            'End
        End Sub
End Class
+2  A: 

If you mean opening the text file with the notepad program via your application then something like the following should do the trick.

System.Diagnostics.Process.Start("notepad.exe", "c:\Application.txt")

See: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

Quintin Robinson
I have tried "Process.Start("C:\Runt.exe")" and your example. They both did not work saying the parameter is incorrect.
Anonymous the Great.
@Anonymous the Great Can you edit your question and post the code you are using? If the process you are trying to start cannot be found you would generally get an exception otherwise the process you are starting is probably expecting arguments and none are being passed.
Quintin Robinson
Posted. :) Thank you.
Anonymous the Great.
@Anonymous the Great Okay, first, in VB there is no escape sequences so you need to replace `"C:\\Runt.exe"` with `"C:\Runt.exe"` for it to be valid. Second, what was the result when you ran the code I posted, was it an exception, a compile time error, did notepad open and say something to the effect of not being able to locate the text file, would you like to create a new one?
Quintin Robinson
I figured it out, thanks.It was because the .EXE was not downloading correctly from SourceForge.
Anonymous the Great.
A: 

You would use the ProcessStart mechanism, see the link below for a tutorial.

This is located within the System.Diagnostics namespace.

Thanks Pete

Process Start Tutorial

Peter