String os=System.getProperty("os.name").toLowerCase(); String command; try { if(os.contains("windows")) { command="shutdown /s /t 600"; } else if(os.contains("linux")||os.contains("mac os x")) { command="shutdown -h +600"; } else throw new Exception("Unsupported OS"); Runtime.getRuntime().exec(command); }catch(Exception ex){ JOptionPane.showMessageDialog(null,ex.getMessage()); }
Tutorials, tips and tricks about java programming language. Answers for many doubts about java programming language. Answering many howtos. Sample java projects and source code, java games, java programs for java practical labs.
How to Schedule a Shutdown in Java - Java Code to Schedule a Shutdown
In this post, we will see how to schedule a shutdown in a computer using java program. For this, we execute the appropriate shutdown command after identifying the operating system. The following java code will schedule a shutdown after a 10 minute from execution of the code.
No comments:
Post a Comment