As far as I know, you are only allowed to kill a process directly from within Java if it was started from the currently running Java code. However, if a certain process was not started from within your Java code, you would need to use a native third-party tool to do the job for you. Thankfully, if you have Windows OS versions greater than Server 2003 or Vista, you can use the TASKKILL.EXE command-line application present in the ~\WINDIR\system32 folder to kill a certain task. Or perhaps, you can use the following code to do this explicitly from within your Java code:
Runtime runtime = Runtime.getRuntime();
String[] killArgs = {"TASKKILL", "/IM", "WINWORD.EXE"};
try
{
Process processToKill = runtime.exec(killArgs);
processToKill.waitFor();
System.out.println(
new StringBuffer()
.append("Process exit code: ")
.append(processToKill.exitValue())
.toString());
System.exit(0);
}
catch(java.io.IOException ex)
{
ex.printStackTrace();
System.exit(1);
}
catch(InterruptedException ex)
{
ex.printStackTrace();
System.exit(1);
}
Tell me if this works for you. I certainly hope this is what you were looking for.
The beginning of knowledge is the fear of God