import com.ice.jni.registry.NoSuchKeyException;
import com.ice.jni.registry.RegStringValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegDWordValue;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import com.ice.jni.registry.RegistryValue;
import java.util.prefs.*;
import java.util.* ;
import java.lang.*;
/**
* @author shanzi
*
*/
class JNIRegistryTest {
/**
* @param args
*/
// create registry key and subkey
public void closeRegistryKey(String mainKey,String subKeyName,String name) {
try {
RegistryKey software = Registry.HKEY_CURRENT_USER
.openSubKey(mainKey);
RegistryKey subKey = software.openSubKey("Microsoft\\Windows\\CurrentVersion\\Policies");
// RegistryKey subKey1 = subKey.openSubKey("Windows");
//RegistryKey subKey2 = subKey1.openSubKey("CurrentVersion");
//RegistryKey subKey3 =subKey2.openSubKey("Policies");
// RegistryKey subKey4 = subKey3.openSubKey("System");
RegistryKey sub = subKey.createSubKey(subKeyName, "");
// create value entries
sub.setValue(new RegDWordValue(sub,name,1,00000001));
subKey.closeKey();
//System.out.println(" 禁用成功!");
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
public void openRegistryKey(String mainKey,String subKeyName,String name) {
try {
RegistryKey software = Registry.HKEY_CURRENT_USER
.openSubKey(mainKey);
RegistryKey subKey = software.openSubKey("Microsoft\\Windows\\CurrentVersion\\Policies");
RegistryKey sub = subKey.createSubKey(subKeyName, "");
// create value entries
sub.setValue(new RegDWordValue(sub,name,1,00000000));
subKey.closeKey();
// System.out.println("取消禁用成功!!");
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
// open and read registry key and value
public void readRegistryValue(String mainKey,String subKey, String name) {
try {
RegistryKey software = Registry.HKEY_CURRENT_USER
.openSubKey(mainKey);
RegistryKey sub = software.openSubKey("Microsoft\\Windows\\CurrentVersion\\Policies\\System");
// RegistryValue subKeyValue = sub.getDWordValue(name);
// System.out.println(subKeyValue);
sub.closeKey();
System.out.println("read registry is succeed!");
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
// delete registry item and value
public void delRegistryItem(String mainKey,String name) {
try {
RegistryKey software = Registry.HKEY_CURRENT_USER
.openSubKey(mainKey);
RegistryKey sub = software.openSubKey("Microsoft\\Windows\\CurrentVersion\\Policies\\System");
sub.deleteSubKey(name);
System.out.println("delete registry "+ mainKey + "--"+name + " is succeed!");
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
}