Read the Registry (this howto is deprecated)Tag(s): DEPRECATED


public class RegistryRead {
 public static void main(String[] args) {
   RegistryRead demo = new RegistryRead();
   demo.doit();
   // IO.PressAnyKey();       
   }
    
 public void doit() {
   displayUserName();
   displayODBCDSN();
   }
    
 public void displayUserName(){
   com.ms.wfc.app.RegistryKey regKey;
   String userName;
   regKey =
     com.ms.wfc.app.Registry.LOCAL_MACHINE.getSubKey
       ("Network\\Logon");
   if (regKey == null) {
     userName = "Unable to get username from Registry!";
     }
   else {
     userName = (String) regKey.getValue("username");
     }
   System.out.println("Username : " + userName);
   }

 public void displayODBCDSN() {
   com.ms.wfc.app.RegistryKey regKey;
   regKey =
     com.ms.wfc.app.Registry.CURRENT_USER.getSubKey
       ("Software\\ODBC\\ODBC.INI\\ODBC Data Sources");
   if (regKey == null) {
     System.out.println("Unable to get ODBC DSN Registry!");
     }
   else {  
     String dsn [] = regKey.getValueNames();
     System.out.println("ODBC DSN defined : ");
     for(int i = 0;  i < dsn.length; i++) { 
       System.out.println(dsn[i]);
       }
     }
 }
}

See also this How-to for a solution using the Sun's JVM and the REG utility.


blog comments powered by Disqus