我已经通过system.diagnostics .process.start(“C:/process.exe”)启动了一个进程 现在我的问题是,如何在vb.net中终止相同的过程
答案 0 :(得分:2)
Start()方法返回一个Process对象。调用它的Kill方法:
Private WithEvents MyProcess As Process
Private Sub MyProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyProcess.Exited
MyProcess = Nothing
End Sub
Private Sub RunIt()
MyProcess = Process.Start("notepad.exe")
End Sub
Private Sub StopIt()
If MyProcess IsNot Nothing Then MyProcess.Kill()
End Sub
答案 1 :(得分:2)
dim myProc as Process
myProc=Process.Start("C:\Process.exe")
...
myProc.kill
答案 2 :(得分:1)
其他人提到了强制进程终止的Kill方法。您可能希望调用CloseMainWindow,以便应用程序可以优雅地关闭。
答案 3 :(得分:0)