/**
* 操作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系统信息
}
}