Calling Taskkill with from within java program requires admin rights
728933Sep 2 2011 — edited Sep 5 2011Hi,
I'm creating a small java app that is supposed to run in the background (javaw) and kill a program when a smartcard is removed from the reader. The issue I have is that it requires to be run with admin privilleges to be able to kill the target application.
Both my java application and the target application is started with my windows user.
Code:
String[] killApp = {"cmd","/c","taskkill /F /fi \"WindowTitle eq Application\""};
Process proc;
Runtime runTime;
runTime = Runtime.getRuntime();
proc = runTime.exec(killApp);
When I run this without admin rights I get the following:
stderr: ERROR: The process with PID 3996 could not be terminated.
stderr: Reason: Access is denied.
When I run it with admin rights it works fine.
When I run the taskkill directly from cmdline it works fine, even though I don't have any admin rights.
When running "whoami" from the java program the output is my username so I know that it runs as the same user that the application that I try to kill.
Anyone have any ideas about this? I suspect that its some UAC error in Windows 7...
Thanks for any input,
Best regards,
Gustav