Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class Processthing {
  4.  
  5. public static void main(String argv[]) {
  6. String targetProcess = JOptionPane
  7. .showInputDialog("Enter process name to terminate: ");
  8. int confirm = JOptionPane.showConfirmDialog(null,
  9. "Are you sure you want to terminate " + targetProcess + "?",
  10. "Terminate Process", JOptionPane.YES_NO_OPTION);
  11. if (confirm == 0) {
  12. terminateProcess(targetProcess);
  13. }
  14. }
  15.  
  16. public static void terminateProcess(String process) {
  17. try {
  18. Runtime.getRuntime().exec("taskkill /F -IM " + process);
  19. JOptionPane.showMessageDialog(null,
  20. "successfully terminated process " + process);
  21. } catch (Exception e) {
  22. JOptionPane.showMessageDialog(null, "failed to terminate process "
  23. + process + " \r\n" + e.getLocalizedMessage());
  24. }
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement