1) Try to run java directly without bat file
Process p = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.Arguments = @"-jar app.jar";
si.FileName = "java";
p.StartInfo = si;
p.Start();
Console.WriteLine(p.Id);
if (!p.HasExited)
p.Kill();
Note, that if you do not want to use try..catch you'll have to use WaitForExit() or HasExited
to wait for termination to complete, otherwise you might see that "process has exited" exception again.
More details How to kill a process without getting a "process has exited" exception?
2) If you should use a bat-file then get the KillProcessAndChildren() method from Kill process tree programmatically in C# (required a reference to System.Management) and call
KillProcessAndChildren(javaProcessID);
It will kill main process, and all its children.
3) And of course, you can still use your original code and enumerate all processes by name
Process[] pp = Process.GetProcessesByName("java");
foreach (Process p in pp)
p.Kill();
pp = Process.GetProcessesByName("cmd");
foreach (Process p in pp)
p.Kill();
but if you have multiple processes of java/cmd, this will delete all of them which might be not a good idea.