Buenas galera!
Fiz um esquema para poder pegar a serial do windows pelo JAVA para um projeto meu aqui… Enfim, montei um script VBS e mandei executar e dpois pego o retorno da execucao do script no console…
Porém, entretanto, toda via! eahuaehuaehuae agora vou ter que mudar o projeto para JWS e não mais um .jar comum com a lib… O problema é que: MEU ESQUEMA DE PEGAR A SERIAL DO WINDOWS PAROU DE FUNCIONAR!
Creio que seja devido a permissoes de execução, mas o detalhe é que, o arquivo é gerado na pasta temporária, so nao consigo executar… E ai? alguem tem alguma sugestão? Abaixo segue o codigo da classe que faz o servço de capturar a serial do Windows.
package com.sgti.utils;
import java.io.*;
/**
*
* @author Arthur Gregorio
*
* @since 1.0
* @version 1.0, 12/07/2011
*/
public class WindowsKey {
private static final File SCRIPT_FILE = new File(
System.getProperty("java.io.tmpdir") + "\\key_grabber.vbs");
public static String grab() throws Exception {
writeScript();
String[] cmd = new String[] {"cmd.exe", "/C", "cscript.exe",
SCRIPT_FILE.getAbsolutePath()};
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
String output = null;
while((line = reader.readLine()) != null) {
if(!line.contains("Microsoft") && !line.equals("")) {
output = line;
}
}
p.destroy();
//SCRIPT_FILE.delete();
return output;
}
private static void writeScript() throws Exception {
if (!SCRIPT_FILE.exists()) {
SCRIPT_FILE.createNewFile();
}
FileWriter output = new FileWriter(SCRIPT_FILE);
output.write(SCRIPT);
output.flush();
output.close();
}
private static final String SCRIPT = "const HKEY_LOCAL_MACHINE = &H80000002"
+ "\nstrKeyPath = \"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" "
+ "\nstrValueName = \"DigitalProductId\" "
+ "\nstrComputer = \".\" "
+ "\ndim iValues() "
+ "\nSet oReg=GetObject(\"winmgmts:{impersonationLevel=impersonate}!\\\\\" "
+ "& strComputer & \"\\root\\default:StdRegProv\") "
+ "\noReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues "
+ "\nDim arrDPID "
+ "\narrDPID = Array() "
+ "\nFor i = 52 to 66"
+ "\nReDim Preserve arrDPID( UBound(arrDPID) + 1 ) "
+ "\narrDPID( UBound(arrDPID) ) = iValues(i) "
+ "\nNext "
+ "\nDim arrChars "
+ "\narrChars = Array(\"B\",\"C\",\"D\",\"F\",\"G\",\"H\",\"J\",\"K\","
+ "\"M\",\"P\",\"Q\",\"R\",\"T\",\"V\",\"W\",\"X\",\"Y\",\"2\",\"3\","
+ "\"4\",\"6\",\"7\",\"8\",\"9\") "
+ "\nFor i = 24 To 0 Step -1 "
+ "\nk = 0"
+ "\nFor j = 14 To 0 Step -1"
+ "\nk = k * 256 Xor arrDPID(j) "
+ "\narrDPID(j) = Int(k / 24) "
+ "\nk = k Mod 24"
+ "\nNext "
+ "\nstrProductKey = arrChars(k) & strProductKey "
+ "\nIf i Mod 5 = 0 And i <> 0 Then strProductKey = \"-\" & strProductKey "
+ "\nNext"
+ "\nWScript.Echo strProductKey "
+ "\nWScript.Quit(0)";
}