在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
函数。你提供了几个零件,并从中建立了一条路径。你想用它来代替手工建立字符串。