Kill process started with System.Diagnostic.Process.Start(“FileName”)

后端 未结 6 1338
生来不讨喜
生来不讨喜 2021-02-05 22:48

I am trying to create an app that will perform actions on specific times (much like the Windows Task Scheduler). I am currently using Process.Start() to launch the file (or exe)

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 23:00

    Process.Start(string,string) returns you a Process resource that you can use to further control the new process.

    Process newProcess = Process.Start("param1", "param2");
    if (newProcess != null && !newProcess.HasExited)
      newProcess.Kill();
    

    The same structure works if you use Process.Start(string), or any other static Process.Start overload.

    Process.Start() is a member function and associates a new or reused Process with the Process component identified by this. Behaviour of this method depends on the properties of the Process identified by this.

提交回复
热议问题