我发现这个代码会杀死一个进程..但是这只适用于1个进程(MS Word)
..我想要的是杀死2个或更多进程。
For Each p As Process In Process.GetProcesses
If String.Compare(p.ProcessName, "WINWORD", True) = 0 Then
p.Kill()
End If
Next
我尝试添加If String.Compare(p.ProcessName, "WINWORD","EXCEL", True) = 0 Then
但此代码错误
我也试试这个If String.Compare(p.ProcessName, "WINWORD , EXCEL", True) = 0 Then
并且这段代码没问题,但它没有读取Winword或excel
答案 0 :(得分:2)
添加更多比较,例如:
if String.Compare(p.ProcessName, "WINWORD", True) = 0 Or String.Compare(p.ProcessName, "EXCEL", True) = 0 Then
p.Kill()
End If
或者,如果列表较大,您可以使用不同的方法。
Dim procsToKill() As String = {"WINWORD", "EXCEL", "NOTEPAD"} ' Add more tho this list
For Each p As Process In Process.GetProcesses
If procsToKill.Contains(p.ProcessName) Then
p.Kill()
End If
Next