Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class Processthing {
- public static void main(String argv[]) {
- String targetProcess = JOptionPane
- .showInputDialog("Enter process name to terminate: ");
- int confirm = JOptionPane.showConfirmDialog(null,
- "Are you sure you want to terminate " + targetProcess + "?",
- "Terminate Process", JOptionPane.YES_NO_OPTION);
- if (confirm == 0) {
- terminateProcess(targetProcess);
- }
- }
- public static void terminateProcess(String process) {
- try {
- Runtime.getRuntime().exec("taskkill /F -IM " + process);
- JOptionPane.showMessageDialog(null,
- "successfully terminated process " + process);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "failed to terminate process "
- + process + " \r\n" + e.getLocalizedMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement