如何使用Visual Basic结束进程?

时间:2013-02-20 20:42:38

标签: vbscript kill kill-process

基本上,我制作了一个既有“RUN BOT”又有“KILL BOT”按钮的程序。我的问题是我用什么代码“杀死”僵尸程序,或者用其他术语关闭单击“RUN BOT”按钮时运行的“batchfile.bat”。感谢所有未来的帮助!

The App with both buttons

以下是目前的代码:

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

1 个答案:

答案 0 :(得分: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