站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题一个windows关机程序

一个windows关机程序

摘要: 一个windows关机程序

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="453" height="86" align="center" valign="top"> 一个windows关机程序,XP下通过.

//java关机代码

/**

* Created by IntelliJ IDEA.

* autor:cofbean

* 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("shutdown "+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{

                CtrWDS.getInstance().exec(str[0]);

                Thread.currentThread().sleep(10000L);

            }

            catch(Exception e){

               //CtrWDS.getInstance().exec(str[0]);

            }

         }

    }

} 

</td> <td width="231" valign="top">
</td></tr> <tr> <td height="20" colspan="2">


</td> </tr> </table> </td> </tr> <tr>


↑返回目录
前一篇: “中文问题没商量”之Ant中的中文问题
后一篇: 使用final变量需要注意