windows定时关机程序

类别:Java 点击:0 评论:0 推荐:
应网友yangxjn需要写的一个windows定时关机程序 . /**
* Created by IntelliJ IDEA.
 * autor:cofbean
 * Date: 2004-3-10
 * Time: 13:41:48
 * qq:21439991
 */   import java.io.IOException;   public class CtrWDS {
    private static CtrWDS ourInstance = null;       private CtrWDS() {
    }       public static CtrWDS getInstance() {
        if (ourInstance == null) {
            ourInstance = new CtrWDS();
        }
        return ourInstance;
    }       public void exec(String cmd) {
        try {
            Runtime.getRuntime().exec(cmd);
        }         catch (IOException e) {
            System.out.println("执行失败");                }
    }       public void shutdown() {
        exec("shutdown -S ");
    }       public void restart() {
        exec("shutdown -R ");
    }       public void logout() {
        exec("shutdown -L ");
    }       public static void main(String[] str) {
        if (str.length == 0) {
            System.out.println("-----------------------\n" +
                    "关机  -s\n" +
                    "重起  -r\n" +
                    "注销  -l\n" +
                    "-----------------------\n");
        }         else{            try{
               Thread.currentThread().sleep(10000L);
            }
            catch(Exception e){
               CtrWDS.getInstance().exec(str[0]);
            }
         }
    }
}
 

本文地址:http://com.8s8s.com/it/it16719.htm