我对杀戮过程有疑问。下面是我用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
答案 0 :(得分:0)
如果您确信要杀死所有cmd进程,可以尝试:
For Each proc As Process In Process.GetProcessesByName("cmd")
proc.Kill()
Next
上面代码的问题是Proc仅引用For Next循环中创建的最后一个流程实例。