my generic blanket answer: windows api. although this time ill do some research http://stackoverflow.com/questions/1916574/how-to-effectively-kill-a-process-in-c-win32
If the process was created via CreateProcess() then you already have the required handle with all access rigths, no need for enumerating all running processes, just call TerminateProcess() on it.
If I did not misunderstand the OP uses CreateProcess to launch a batch script,
Witch in turn runs a 3rd Java process (somthing.jar) witch he don`t have the HANDLE to.
Then why the hell needs the batch script after all ? Why he can't launch the java process directly ?
Regarding your code, if there are more than one java applications running on that system, the code will pick one of them randomly and close the wrong one.
You probably need to get command line for each java process to see which one contains *.jar file name executed.
Regarding your code, if there are more than one java applications running on that system, the code will pick one of them randomly and close the wrong one.
The OP does state that they want to find the Java process which is the child process of the one which runs the launching batch file.
As the PROCESSENTRY32 struct includes a th32ParentProcessID member, the process ID returned by CreateProcess can be used to filter the results returned by Process32First/Process32Next to identify the correct child process.