whyclj
2019-02-19 76ad368d8977602e6d8de689ddc7c3d595fb173b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.backup;
 
import java.io.*;
 
public class RegQuery {
 
    private static final String REGQUERY_UTIL = "reg query ";
    private static final String REGSTR_TOKEN = "REG_SZ";
    private static final String REGDWORD_TOKEN = "REG_DWORD";
 
    private static final String PERSONAL_FOLDER_CMD = REGQUERY_UTIL
            + "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\" + "Explorer\\Shell Folders\" /v Personal";
    private static final String CPU_SPEED_CMD = REGQUERY_UTIL
            + "\"HKLM\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\"" + " /v ~MHz";
    private static final String CPU_NAME_CMD = REGQUERY_UTIL
            + "\"HKLM\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\"" + " /v ProcessorNameString";
    private static final String HTTP_DEFAULT_BROWSERURI = REGQUERY_UTIL
            + "\"HKEY_CLASSES_ROOT\\http\\shell\\open\\command\"" + "";// http\\shell\\open\\ddeexec\\Topic
    private static final String HTTP_DEFAULT_BROWSERNAME = REGQUERY_UTIL
            + "\"HkEY_CLASSES_ROOT\\http\\shell\\open\\ddeexec\\Topic\"" + "";
 
    private static final String MYSQL_SETUP_PATH = REGQUERY_UTIL
            + "\"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\BMS_FBSDEV\\Parameters\"" + "";
 
    public static String getCurrentUserPersonalFolderPath() {
        try {
            Process process = Runtime.getRuntime().exec(MYSQL_SETUP_PATH);
            StreamReader reader = new StreamReader(process.getInputStream());
 
            reader.start();
            process.waitFor();
            reader.join();
 
            String result = reader.getResult();
            System.out.println(result + "****");
            int p = result.indexOf(REGSTR_TOKEN);
 
            if (p == -1)
                return null;
 
            return result.substring(p + REGSTR_TOKEN.length()).trim();
        } catch (Exception e) {
            return null;
        }
    }
 
    public static String getCPUSpeed() {
        try {
            Process process = Runtime.getRuntime().exec(CPU_SPEED_CMD);
            StreamReader reader = new StreamReader(process.getInputStream());
 
            reader.start();
            process.waitFor();
            reader.join();
 
            String result = reader.getResult();
            int p = result.indexOf(REGDWORD_TOKEN);
 
            if (p == -1)
                return null;
 
            // CPU speed in Mhz (minus 1) in HEX notation, convert it to DEC
            String temp = result.substring(p + REGDWORD_TOKEN.length()).trim();
            return Integer.toString((Integer.parseInt(temp.substring("0x".length()), 16) + 1));
        } catch (Exception e) {
            return null;
        }
    }
 
    public static String getCPUName() {
        try {
 
            Process process = Runtime.getRuntime().exec(HTTP_DEFAULT_BROWSERURI);
            StreamReader reader = new StreamReader(process.getInputStream());
 
            reader.start();
            process.waitFor();
            reader.join();
 
            String result = reader.getResult();
            int p = result.indexOf(REGSTR_TOKEN);
 
            if (p == -1)
                return null;
 
            return result.substring(p + REGSTR_TOKEN.length()).trim();
        } catch (Exception e) {
            return null;
        }
    }
 
    static class StreamReader extends Thread {
        private InputStream is;
        private StringWriter sw;
 
        StreamReader(InputStream is) {
            this.is = is;
            sw = new StringWriter();
        }
 
        public void run() {
            try {
                int c;
                while ((c = is.read()) != -1)
                    sw.write(c);
            } catch (IOException e) {
                ;
            }
        }
 
        String getResult() {
            return sw.toString();
        }
    }
 
    public static void main(String s[]) {
        System.out.println("Personal directory : " + getCurrentUserPersonalFolderPath());
        // System.out.println("CPU Name : " + getCPUName());
        // System.out.println("CPU Speed : " + getCPUSpeed() + " Mhz");
    }
}