Java examples for Native OS:Windows
Java wrapper for Windows registry API RegQueryInfoKey()
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.prefs.Preferences; public class Main { private static final Preferences systemRoot = Preferences.systemRoot(); private static Method windowsRegQueryInfoKey = null; /**//from www . ja v a 2s . c om * Java wrapper for Windows registry API RegQueryInfoKey() * * @param hKey * the Native Handle * @return int[5] retval[SUBKEYS_NUMBER] will give then number of sub keys * under the queried key. retval[ERROR_CODE] will give the error * code. retval[VALUES_NUMBER] will give the number of values under * the given key. retval[MAX_KEY_LENGTH] will give the length of the * longes sub key. retval[MAX_VALUE_NAME_LENGTH] will give length of * the longes value name. */ public static int[] RegQueryInfoKey(int hKey) { try { return (int[]) windowsRegQueryInfoKey.invoke(systemRoot, new Object[] { new Integer(hKey) }); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return new int[0]; } }