0

基本上,我制作了一个同时具有“RUN BOT”和“KILL BOT”按钮的程序。我的问题是我使用什么代码来“杀死”机器人,或者换句话说,在单击“RUN BOT”按钮时关闭它正在运行的“batchfile.bat”。感谢所有未来的帮助!

带有两个按钮的应用程序

这是到目前为止的代码:

Public Class Form1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Process.Start("C:\batchfile.bat")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class
4

1 回答 1

1

将 Process.Start() 方法返回的 Process 实例存储在实例变量中。然后,调用更适合您需要的CloseMainWindowKill 。

编辑:这适用于 VS 2010

Public Class Form1
Private p As Process

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    p = Process.Start("c:\batchfile.bat")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    p.Kill()
End Sub
End Class
于 2013-02-20T20:56:29.523 回答