2010-08-06 41 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