Posts tagged ‘Registro Windows Java winregstry’

julio 8, 2011

Funcion Recursiva para Eliminar una Llave en el Registro de Windows (WinRegistry)

public void delKey(Key root,Key a,Key b){
		try {
			List listKeys = registry.listKeys(a);
			String subKey="";
			Key newKey=null;
			Iterator iterator=null;
			try{
				iterator = listKeys.iterator();
				while(iterator.hasNext()){
					newKey = registry.openKey(a, iterator.next());
					if(root == Regor.HKEY_LOCAL_MACHINE)subKey=newKey.getPath().substring(19);
					subKey=newKey.getPath().substring(18);
					registry.listKeys(newKey).size();
					delKey(root,newKey,b);
				    }
				delKey(root,a,b);
				}catch (Exception exception) {
				boolean deleted=false;
					try{
						registry.delKey(root,subKey);
						deleted=true;
					}catch (Exception ex) {
						deleted=false;
						return;
					}
					if(!deleted){
						newKey = registry.openKey(a, iterator.next());
						delKey(root,newKey,b);
					}else{	
                                                delKey(root,a,b);
					}
				}
		} catch (RegistryErrorException e) {
			e.printStackTrace();
		}
}