vb.net 如何在 Visual Basic 2010 中打开程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3425955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:59:30  来源:igfitidea点击:

How would I open a program within Visual Basic 2010?

vb.netprocess

提问by Anonymous the Great.

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

如何在 Visual Basic 2010 中打开程序?(就像在 Visual Basic 项目中从“C:\”运行“Application.txt”一样。

    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

回答by Quintin Robinson

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

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

回答by Peter

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

您将使用 ProcessStart 机制,请参阅下面的链接以获取教程。

This is located within the System.Diagnostics namespace.

它位于 System.Diagnostics 命名空间内。

Thanks Pete

谢谢皮特

Process Start Tutorial

流程启动教程