操作Windows属性工具类

/**
 * 操作Windows属性工具类
 *
 */
public class WindowsUtil {
	/**
	 * 获取系统开机时间
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static String readSystemStartTime() throws IOException, 
    InterruptedException { 
        Process process = Runtime.getRuntime().exec( 
            "cmd /c net statistics workstation"); 
        String startUpTime = ""; 
        BufferedReader bufferedReader = new BufferedReader( 
            new InputStreamReader(process.getInputStream())); 
        int i = 0; 
        String timeWith = ""; 
        while ((timeWith = bufferedReader.readLine()) != null) { 
           if (i == 3) { 
//               System.out.println(timeWith); 
               startUpTime = timeWith; 
         } 
        i++; 
       } 
        process.waitFor(); 
        //处理字符串
        startUpTime = startUpTime.substring(8);
        String s= startUpTime;
        System.out.println("系统开机时间:"+s);
        String s1 = s.substring(0, 8);
//		System.out.println("s1:"+s1);
		
		String ss = s.substring(9,11);
//		System.out.println("ss:"+ss);
		
		String s2 = s.substring(12);

		//System.out.println("s2:"+s2);
		
		if(ss.equals("下午")){
			int hour = 0;
			try {
			  hour	 = Integer.parseInt(s2.substring(0,2));
			  hour = hour+12;
			} catch (Exception e) {
				e.printStackTrace();
			}
			s2 = hour+s2.substring(2)+":00";
			System.out.println(s2);
		}else{
			s2 = s2+":00";
		}
		
		String time = s1+" "+s2;
		
		long mi = 0;
		try {
			mi = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(time).getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
		String rtime = DateTool
			.getDateTime(new Date(
				mi	
			));
        
        return rtime; 
} 
	
	/**
	  * Reg 参数说明
	  * /v       所选项之下要添加或删除的值名
	  * /t       RegKey 数据类型(reg_sz字符串)
	  * /d       要分配给添加的注册表 ValueName 的数据
	  * /f         不用提示就强行删除
	  */
	 public static void addStart() throws IOException{
	  String regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
	  String myAppName = "Ecollect";
	  String exePath = "\"C:\\Program Files\\Ecollect\\ECollect.exe\"";
	  String s = "reg add "+regKey+" /v "+myAppName+" /d "+exePath;
	  System.out.println(s);
	  Runtime.getRuntime().exec(s);
	 }
	/**
	 * 获取操作系统名称
	 * @return
	 */
	public static String getOSName(){
		return System.getProperty("os.name");
	}
	 
	public static void main(String[] args) throws Exception{
		System.out.println(System.getProperty("os.name"));;//得到操作系统名字 
		System.out.println(System.getProperty("sun.os.patch.level"));;//得到操作系统版本 
		System.out.println(System.getProperty("sun.cpu.isalist"));;//得到CPU系统信息 
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值