在Visual Studio Express中創建一個新的WinForms應用程序並拖動窗體上的兩個按鈕。按你喜歡的設計。雙擊每個按鈕以編輯.Click
事件。
的方法來啓動一個新的Windows進程Process.Start()
Private Sub Button1_Click(sender as Object, e as EventArgs) Handles Button1.Click
RunAndClose(IO.Path.Combine(Application.StartupPath, "x86", "setup.exe"))
End Sub
Private Sub Button2_Click(sender as Object, e as EventArgs) Handles Button2.Click
RunAndClose(IO.Path.Combine(Application.StartupPath, "x64", "setup.exe"))
End Sub
Private Sub RunAndClose(filename As String)
If IO.File.Exists(filename) = False Then
MessageBox.Show(String.Format("The selected installer {0}{0}{1}{0}{0} could not be found!", vbCrLf, filename), "Installer not found", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Process.Start(filename)
Me.Close
End If
End Sub
您創建一個子RunAndClose
實際做的工作。您有文件名作爲子參數。檢查您要啓動的文件是否存在(IO.File.Exists
)。如果是這樣,啓動它並關閉應用程序,如果不顯示錯誤消息。
Button-Subs使用IO.Path.Combine
函數。你提供了幾個零件,並從中建立了一條路徑。你想用它來代替手工建立字符串。