0

这是我正在使用的代码:

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

我想知道如何让 Button1_Click 杀死“batchfile.bat”?批处理文件正在打开一个 CMD 提示符,如果这对任何人都有帮助的话。

4

1 回答 1

2

您需要在表单的字段中启动Process返回的实例。Process.Start()

然后,您可以调用该Kill()方法。

例如:

Public Class Form1
    Private mySubTask As Process

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        mySubTask = Process.Start("C:\batchfile.bat")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mySubTask.Kill()
    End Sub

如果用户单击开始两次,您将需要弄清楚该怎么做。

于 2013-02-22T04:38:14.423 回答