从窗体closures命令窗口

我有一个简单的Node.js程序,通过从winform中单击button执行,工作正常,但我需要终止Node.js程序并closures另一个button单击命令提示符。如何实现这一目标?

干杯杰夫

如果你开始这个过程,你有一个processtypes的对象。 这个对象支持kill ,会立即结束进程。

更新的代码

 Public Class Form1 Dim MyProcess As Process Private Sub btnStartPrcoess_Click(sender As Object, e As EventArgs) Handles btnStartPrcoess.Click If MyProcess Is Nothing Then MyProcess = Process.Start("cmd.exe", "arguments") End If End Sub Private Sub btnKillProcess_Click(sender As Object, e As EventArgs) Handles btnKillProcess.Click If MyProcess IsNot Nothing Then MyProcess.Kill() MyProcess.Close() MyProcess = Nothing End If End Sub End Class 

如果您需要从不同的方法结束进程,则需要在课程级别上声明stream程variables。 甚至Process.Start()也有一个types为process的返回值。 所以没有必要去search这个过程 – 你已经知道了!

UPDATE

这或多或less是无稽之谈,做这样的事情:

 MyProcess = Process.Start("cmd.exe", "/k notepad.exe") 

因为它只是启动cmd.exe,然后启动notepad.exe。 当然, Process现在“指向”cmd.exe,而不是notepad.exe。 如果你想记事本运行,这显然是最好的解决scheme,直接启动它:

 MyProcess = Process.Start("notepad.exe", "arguments for notepad, if needed") 

您已经使用Process.Start("cmd.exe", "/k C:\Users\PROG21\Desktop\chat\exit.exe")来启动该进程。 所以声明一个全局的Processvariables并尝试;

 Process exeProcess; 

点击开始button:

  exeProcess = Process.Start("cmd.exe", "/k C:\Users\PROG21\Desktop\chat\exit.exe"); 

点击停止button;

 exeProcess.Kill();