Reputation:
So, I have started a process in java using exec method in Runtime class. Now, how I invoked this is as follows.
Runtime r=Runtime.getRuntime();
Process p=null;
String s="E:\\Softwares\\fiddler4setup.exe";
p=r.exec("cmd /c"+s);
Now, when I trying to destroy the process using p.destroy() method. Fiddler4setup.exe is still running. I have been searching ways to close this for like a week. Even here, there is no particular correct answer for this sort of problem. Please kindly help me with this.
Also, running the file directly is not working as it's displaying some 704 error I guess. Then, I saw this solution of using "cmd /c".
Thank you.
Upvotes: 1
Views: 1699
Reputation: 59950
To kill your process you have to use :
Taskkill /IM YourProcess.exe /F
Or with PID
Taskkill /PID 26356 /F
So your program should look like this :
Runtime r = Runtime.getRuntime();
Process p = r.exec("Taskkill /IM fiddler4setup.exe /F");
Note you can get the PID of your process using this command tasklist
in your cmd, this will be better if you use PID to avoid all problem of path.
EDIT
There no clear way to run your script as administrator mode, there are some question here hope can gives you and idea :
Run command prompt as Administrator
Java: run as administrator
Run Java file as Administrator with full privileges
Upvotes: 1