elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Serial USB, leyendo registros de windows
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Serial USB, leyendo registros de windows  (Leído 2,104 veces)
Maurice_Lupin


Desconectado Desconectado

Mensajes: 356

GPS


Ver Perfil WWW
Serial USB, leyendo registros de windows
« en: 21 Diciembre 2011, 23:25 pm »

Tratando de obtener el serial de un USB evitando utilizar la api de windows, en java, googleando encontre un ejm acceder a registros de windows desde java. Modifique y resultó esto, el problema es que los registros no se actualizan cuando quitas un USB  :o bueno quizá alguien tenga alguna sugerencia.

Código
  1. import java.io.*;
  2.  
  3. public class RegQuery {
  4.  
  5.  private static final String REGQUERY_UTIL = "reg query ";
  6.  private static final String REGSTR_TOKEN = "REG_SZ";
  7.  private static final String REGDWORD_TOKEN = "REG_DWORD";
  8.  
  9.  
  10.  private static final String SERIAL_USB = REGQUERY_UTIL +
  11.   "HKLM\\SYSTEM\\CurrentControlSet\\Control\\DeviceClasses\\{a5dcbf10-6530-11d2-901f-00c04fb951ed}\\";
  12.   //+ " /v DeviceInstance";
  13.  
  14.  
  15.  
  16.    public static String getSERIALS_USB() {
  17.    try {
  18.      Process process = Runtime.getRuntime().exec(SERIAL_USB);
  19.      StreamReader reader = new StreamReader(process.getInputStream());
  20.      String ret, cad[], su[];
  21.      int p = -1;
  22.      reader.start();
  23.      process.waitFor();
  24.      reader.join();
  25.      String result = reader.getResult();      
  26.  
  27.      cad = result.split("\n");      
  28.      ret = "";
  29.      for(int i=0; i < cad.length; i++) {
  30.          p = cad[i].indexOf("USB");
  31.          if (p != -1 ) {
  32.              cad[i] = cad[i].substring(p);              
  33.              su = cad[i].split("#");
  34.              ret += su[2]+"\n";
  35.          }
  36.      }            
  37.      return ret;
  38.    }
  39.    catch (Exception e) {
  40.      return null;
  41.    }
  42.  }
  43.  
  44.  
  45.  
  46.  static class StreamReader extends Thread {
  47.    private InputStream is;
  48.    private StringWriter sw;
  49.  
  50.    StreamReader(InputStream is) {
  51.      this.is = is;
  52.      sw = new StringWriter();
  53.    }
  54.  
  55.    public void run() {
  56.      try {
  57.        int c;
  58.        while ((c = is.read()) != -1)
  59.          sw.write(c);
  60.        }
  61.        catch (IOException e) { ; }
  62.      }
  63.  
  64.    String getResult() {
  65.      return sw.toString();
  66.    }
  67.  }
  68.  
  69.  public static void main(String s[]) {
  70.  
  71.    System.out.println("Seriales :\n" + getSERIALS_USB());
  72.  }
  73. }
  74.  
  75.  

Saludos.


« Última modificación: 21 Diciembre 2011, 23:32 pm por Maurice_Lupin » En línea

Un error se comete al equivocarse.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[?]Registros de Windows <.<
ASM
Иōҳ 1 3,305 Último mensaje 10 Marzo 2010, 00:22 am
por Eternal Idol
[Registros] existe algún registro para Outlook en los registros de windows?
Windows
moikano→@ 5 6,851 Último mensaje 14 Febrero 2011, 14:56 pm
por dantemc
Escribiendo/leyendo un byte en el puerto serial com1
Programación C/C++
Sutano 2 3,518 Último mensaje 27 Agosto 2012, 23:32 pm
por Sutano
Registros de Windows arruinados
Windows
EndlessLoop 5 2,431 Último mensaje 2 Febrero 2015, 19:06 pm
por EndlessLoop
serial de windows
Windows
ducafra 3 3,054 Último mensaje 25 Septiembre 2020, 18:23 pm
por EdePC
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines