Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have written a code to close specified applications but this code does not close the application which has been opened as an administrator.
 private static void restrict ()
    {
        try {
            String strOutput="", strError="";
            Process p = Runtime.getRuntime().exec(new String[]{"cmd", "/c", "tasklist /svc"});
           BufferedReader stdInput= new BufferedReader(new InputStreamReader(p.getInputStream()));
           BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
           
        while (strOutput != null) {
if(strOutput.toLowerCase().contains("winword.exe"))
{
    System.out.println("found specified file");
    Runtime.getRuntime().exec("taskkill /im winword.exe");
    System.out.println("killed.");
}
if (strOutput.length() < 1) {
} else {
System.out.println(strOutput);
}

strOutput = stdInput.readLine();
}

strError = stdError.readLine();

if (strError != null) {
System.out.println("An error occured");

while (strError != null) {
System.out.println(strError);
strError = stdError.readLine();
}
}
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
            
        }
    }


any body please help me with this.
Posted
Comments
Richard MacCutchan 5-Aug-14 11:53am    
You cannot force kill a process that has a higher authority level.
Sergey Alexandrovich Kryukov 5-Aug-14 18:03pm    
Why would you even try that? A good principle is: everything is terminated by its creator.
—SA

1 solution

Apparently you cannot do it. The question is: why? My advice is: use the principle: "everything is terminated by its creator". Therefore, review your whole architecture. The one based on the idea to create some process by one process and close by another is wrong, even if you had enough priority to terminate the process.
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900