Vb.net 正在终止进程cmd.exe ping.exe和conhost.exe

Vb.net 正在终止进程cmd.exe ping.exe和conhost.exe,vb.net,cmd,ping,Vb.net,Cmd,Ping,我对杀戮过程有疑问。下面是我用VB语言编写的代码。 我似乎无法杀死ping.exe和conhost.exe,即使创建了70个cmd,我也只能杀死1个cmd.exe。 多谢各位 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim xl As Integer = 368 Dim value As Integer =

我对杀戮过程有疑问。下面是我用VB语言编写的代码。 我似乎无法杀死ping.exe和conhost.exe,即使创建了70个cmd,我也只能杀死1个cmd.exe。 多谢各位

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim xl As Integer = 368
    Dim value As Integer = 0
    For value = 0 To 69
        Proc.StartInfo = New ProcessStartInfo("C:\Windows\System32\cmd.exe")
        Proc.StartInfo.Arguments = ("cmd.exe /k" + TextBox1.Text + " " + ipAdd.Text + " " + TextBox2.Text + " " + TextBox3.Text)
        Proc.StartInfo.RedirectStandardInput = True
        Proc.StartInfo.RedirectStandardOutput = False
        Proc.StartInfo.UseShellExecute = False
        Proc.StartInfo.CreateNoWindow = True
        Proc.Start()
    Next
    Timer1.Enabled = False

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Proc.Kill()
    Proc.Close()
    'Proc.Start("cmd.exe", "/C choice /C Y /N /T 3 & Del " + Application.ExecutablePath)
    'Application.Exit()
End Sub

如果您确信要终止所有cmd进程,可以尝试:

    For Each proc As Process In Process.GetProcessesByName("cmd")
        proc.Kill()
    Next

上面代码的问题是Proc只引用在For Next循环中创建的最后一个进程实例。

如果您确信要终止所有cmd进程,可以尝试:

    For Each proc As Process In Process.GetProcessesByName("cmd")
        proc.Kill()
    Next
上面代码的问题是Proc只引用在For Next循环中创建的最后一个流程实例