2010-08-06 46 views
1

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

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 

回答

4

如果你的意思是通过您的应用程序中打开用记事本程序中的文本文件,然后像下面应该做的伎俩。

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

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

+0

我已经试过 “的Process.Start(” C:\ Runt.exe “)” 和你的榜样。他们都没有说这个参数是不正确的。 – 2010-08-06 17:05:39

+1

@Anonymous the Great你能编辑你的问题并发布你正在使用的代码吗?如果你试图启动的进程无法找到,你通常会得到一个异常,否则你开始的进程可能需要参数而没有被传递。 – 2010-08-06 17:30:16

+0

已发布。 :) 谢谢。 – 2010-08-06 21:52:29

0

您将使用ProcessStart机制,见下面的链接教程

这是LO在System.Diagnostics命名空间内。

感谢 皮特

Process Start Tutorial