Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can get desired process from list of running processes and then wait it for exit:</p> <pre><code>var javaws = File.Exists(@"C:\Program Files\Java\jre6\bin\javaws.exe") ? @"C:\Program Files\Java\jre6\bin\javaws.exe" : @"C:\Program Files (x86)\Java\jre6\bin\javaws.exe"; var psi = new ProcessStartInfo(javaws, String.Format("http://{0}:/appstart.jnlp", hostAddress)); // make sure child process is already started Process.Start(psi).WaitForExit(); foreach (Process p in Process.GetProcessesByName("javaw")) { p.WaitForExit(); } </code></pre> <p>To kill not only <em>javaw</em>, but all of child processes you need to get process ID of <em>javaws</em> and compare it to parent ID of all running processes. Here is complete code: (extension method comes from <a href="https://stackoverflow.com/questions/394816/how-to-get-parent-process-in-net-in-managed-way">here</a>)</p> <pre><code>class Program { static void Main(string[] args) { var javaws = File.Exists(@"C:\Program Files\Java\jre6\bin\javaws.exe") ? @"C:\Program Files\Java\jre6\bin\javaws.exe" : @"C:\Program Files (x86)\Java\jre6\bin\javaws.exe"; var psi = new ProcessStartInfo(javaws, String.Format("http://{0}:/appstart.jnlp", hostAddress)); var parentProc = Process.Start(psi); parentProc.WaitForExit(); foreach (Process p in Process.GetProcesses()) { if (p.Parent().Id == parentProc.Id) p.WaitForExit(); } } } public static class ProcessExtensions { private static string FindIndexedProcessName(int pid) { var processName = Process.GetProcessById(pid).ProcessName; var processesByName = Process.GetProcessesByName(processName); string processIndexdName = null; for (var index = 0; index &lt; processesByName.Length; index++) { processIndexdName = index == 0 ? processName : processName + "#" + index; var processId = new PerformanceCounter("Process", "ID Process", processIndexdName); if ((int)processId.NextValue() == pid) { return processIndexdName; } } return processIndexdName; } private static Process FindPidFromIndexedProcessName(string indexedProcessName) { var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName); return Process.GetProcessById((int)parentId.NextValue()); } public static Process Parent(this Process process) { return FindPidFromIndexedProcessName(FindIndexedProcessName(process.Id)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload