Một ví dụ sẽ là như thế này:
import com.ice.jni.registry.*;
public class DeleteEnvironmentVar{
public DeleteEnvironmentVar(String variable, String value) throws Exception {
RegistryKey machine = Registry.getTopLevelKey("HKEY_LOCAL_MACHINE");
RegistryKey environment = machine.openSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", RegistryKey.ACCESS_WRITE);
try {
if (value == null) { //Delete the variable in case value is empty
environment.deleteValue(variable);
}
}
catch(NoSuchValueException nsve) {}
catch(NoSuchKeyException nske) {}
}
}
Chỉ cho phép một phần cụ thể duy nhất cho ứng dụng của bạn. – boutta
Thực tế là Preferences sử dụng Registry trên các hệ thống Windows chỉ là một chi tiết thực hiện - Preferences không phải là một API đăng ký. –