import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RegReader {
public static final HashMap<String, String> readRegistry(String location, List<String> keyList){
HashMap<String, String> regKeyValue = new HashMap<String, String>();
for (String key : keyList) {
try {
// Run reg query, then read output with StreamReader (internal class)
Process process = Runtime.getRuntime().exec("reg query " + '"'+ location + "\" /v " + key);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
// Parse out the value
String[] parsed = reader.getResult().split("\\s+");
if (parsed.length > 1) {
regKeyValue.put(key, parsed[parsed.length-1]);
}
else
regKeyValue.put(key, null);
} catch (Exception e) {}
}
return regKeyValue;
}
static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw= new StringWriter();
public StreamReader(InputStream is) {
this.is = is;
}
public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
} catch (IOException e) {
}
}
public String getResult() {
return sw.toString();
}
}
public static void createHTML(HashMap<String,String> datas) {
try {
String basePath = new File(".").getCanonicalPath();
File f = new File(basePath + "/src" + "/Registry.html");
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
writer.write("<html>");
writer.write("<body>");
for (String key : datas.keySet()) {
writer.write("<span>" + key + " : " + datas.get(key) + "</span></br>");
}
writer.write("</body>");
writer.write("</html>");
writer.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
String location = "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS";
List<String> keyList = new ArrayList<String>();
//Add List of Keys for getting its value
keyList.add("SystemSKU");
//keyList.add("VersionExt");
HashMap<String, String> value = RegReader.readRegistry(location, keyList);
createHTML(value);
for (String key : value.keySet()) {
System.out.println(key + " : " + value.get(key));
}
}
}
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class RegReader {
public static final HashMap<String, String> readRegistry(String location, List<String> keyList){
HashMap<String, String> regKeyValue = new HashMap<String, String>();
for (String key : keyList) {
try {
// Run reg query, then read output with StreamReader (internal class)
Process process = Runtime.getRuntime().exec("reg query " + '"'+ location + "\" /v " + key);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
// Parse out the value
String[] parsed = reader.getResult().split("\\s+");
if (parsed.length > 1) {
regKeyValue.put(key, parsed[parsed.length-1]);
}
else
regKeyValue.put(key, null);
} catch (Exception e) {}
}
return regKeyValue;
}
static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw= new StringWriter();
public StreamReader(InputStream is) {
this.is = is;
}
public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
} catch (IOException e) {
}
}
public String getResult() {
return sw.toString();
}
}
public static void createHTML(HashMap<String,String> datas) {
try {
String basePath = new File(".").getCanonicalPath();
File f = new File(basePath + "/src" + "/Registry.html");
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
writer.write("<html>");
writer.write("<body>");
for (String key : datas.keySet()) {
writer.write("<span>" + key + " : " + datas.get(key) + "</span></br>");
}
writer.write("</body>");
writer.write("</html>");
writer.close();
} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
String location = "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS";
List<String> keyList = new ArrayList<String>();
//Add List of Keys for getting its value
keyList.add("SystemSKU");
//keyList.add("VersionExt");
HashMap<String, String> value = RegReader.readRegistry(location, keyList);
createHTML(value);
for (String key : value.keySet()) {
System.out.println(key + " : " + value.get(key));
}
}
}
No comments:
Post a Comment