使用来自 TextBox 的文件路径打开带有 Button 的“.exe”

Open a ".exe" with a Button using a file path from a TextBox

我有一个名为 TextBox1 的文本框,它由一个使用 OpenFileDialog 获取文件路径的按钮填充。我想要一个按钮(Button3)以2小时的间隔一个接一个地启动几个进程,然后关闭它并打开下一个。

我总共有 4 个不同的文本框(TextBox1、TextBox2、TextBox3 和 TextBox4)和 4 个不同的文件路径,我想用我之前提到的间隔用相同的按钮打开它们。

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Please Select a File"
        OpenFileDialog1.InitialDirectory = "C:temp"
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        Dim strm As System.IO.Stream
        strm = OpenFileDialog1.OpenFile()
        TextBox1.Text = OpenFileDialog1.FileName.ToString()
        If Not (strm Is Nothing) Then

            'insert code to read the file data

            strm.Close()
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        OpenFileDialog2.Title = "Please Select a File"
        OpenFileDialog2.InitialDirectory = "C:temp"
        OpenFileDialog2.ShowDialog()
    End Sub

    Private Sub OpenFileDialog2_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog2.FileOk
        Dim strm As System.IO.Stream
        strm = OpenFileDialog2.OpenFile()
        TextBox3.Text = OpenFileDialog2.FileName.ToString()
        If Not (strm Is Nothing) Then

            'insert code to read the file data

            strm.Close()
        End If
    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    End Sub
End Class

要启动新进程,请使用:

dim myProcess = Process.start(filename)

您不需要执行以下操作的代码:

    Dim strm As System.IO.Stream
    strm = OpenFileDialog2.OpenFile()
    If Not (strm Is Nothing) Then
        strm.Close()
    End If

这正在打开 exe 文件,就像它试图从中读取数据一样。

而是使用

   dim process = Process.Start(OpenFileDialogX.Filename)

注意:您的初始目录似乎是 c:temp 而不是 c:\temp,因为它可能应该是