杀死现有流程

时间:2013-02-21 04:31:25

标签: vb.net process kill

我正在尝试构建一个启动的脚本,然后停止一个进程:

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 
    (DESIRED CODE HERE)
    End Sub
End Class

Button2启动batchfile.bat的流程。我需要找到一种方法来点击Button1时结束此过程。有没有相对简单的方法来做到这一点?

1 个答案:

答案 0 :(得分:1)

请查看此示例代码

  Dim p1 As Process
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        p1 = Process.Start("C:\Users\082043\Desktop\akshay.bat")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        p1.Kill()
    End Sub