这里介绍的是利用registry向windows系统写注册表的过程:
首先下载registry,我这里用的是registry-3.1.3.zip,解压后在bin目录下会有两个必须的文件:
1、registry.jar,
2、ICE_JNIRegistry.dll(动态链接库文件),
把.jar文件放到lib下面,至于.dll文件就看你的配置情况了,一般的情况下,如果是非WEB工程,你把它直接拷贝到工程的根目录就可以,如果是web工程,你把它拷贝到jdk的bin目录下面就可以。
example:
//导包
import com.ice.jni.registry.NoSuchKeyException;
import com.ice.jni.registry.RegDWordValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import com.ice.jni.registry.RegistryValue;
//
public class Registery {
public static void main(String[] args){
try {
RegistryKey software = Registry.HKEY_CURRENT_USER.openSubKey("Software");
RegistryKey microsoft =software.openSubKey("Microsoft");
RegistryKey explorer =microsoft.openSubKey("Internet Explorer");
RegistryKey subKey = explorer.createSubKey("Styles", "");
subKey.setValue(new RegDWordValue(subKey,"MaxScriptStatements",RegistryValue.REG_DWORD,9999999));
subKey.closeKey();
} catch (NoSuchKeyException e) {
e.printStackTrace();
} catch (RegistryException e) {
e.printStackTrace();
}
}
}