Advertisement
Guest User

Untitled

a guest
May 24th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.io.IOException;
  2.  
  3. class ShutDownManager
  4. {
  5. public static void shutDownSystem()
  6. {
  7. String property = System.getProperty("os.name" );
  8. System.out.println( property );
  9.  
  10. if ( property.toLowerCase().contains("windows") )
  11. {
  12. String[] commands = { "shutdown", "-s" };
  13.  
  14. try {
  15. //do something before shutdown..
  16. Process process = Runtime.getRuntime().exec( commands );
  17. }
  18. catch (IOException e)
  19. {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. if ( property.toLowerCase().contains("linux") )
  25. {
  26. String[] commands = { "shutdown", "-p", "now" };
  27.  
  28. try {
  29. //do something before shutdown..
  30. Process process = Runtime.getRuntime().exec( commands );
  31. //process.waitFor();
  32. }
  33. catch (IOException e)
  34. {
  35. e.printStackTrace();
  36. }
  37. }
  38. }
  39. }
  40.  
  41.  
  42. public class Main
  43. {
  44. public static void main( String[] args )
  45. {
  46. new ShutDownManager().shutDownSystem();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement