Last active
November 18, 2016 15:44
-
-
Save robophil/fea791be22d8eb264698 to your computer and use it in GitHub Desktop.
Registry management @ Tochukwu ogbu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class RegManager{ | |
public static void main(String[] args){ | |
/** | |
Create a class and put this methods inside. | |
1. For inserting your registration key into the registry | |
2. For reading values from the registry | |
import the classes in the registry.zip to this class | |
and add the lib in the lib.zip to this project class path | |
@Tochukwu Ogbu | |
**/ | |
/** | |
path: where in the registry u wanna save ur key | |
name: the name of the the subsection in that path that would hold ur key(word or db-word or quad-word) | |
val: the key u wanna save in the registry | |
String path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | |
returns true if successful and false otherwise | |
**/ | |
public boolean setRegValue(String path, String name, String value){ | |
try { | |
WinRegistry.writeStringValue(WinRegistry.HKEY_CURRENT_USER, path, name, val, 0); | |
}catch(Exception e){ | |
return false; | |
} | |
return true; | |
} | |
/** | |
path: where in the registry u wanna extract a key from | |
name: the name of the the subsection in that path that u wanna extract a key from(word or db-word or quad-word) | |
String path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | |
returns the true if the key matches what ur looking for(case sensitive) and false otherwise | |
**/ | |
public boolean getRegValue(String path, String name, String what_ur_looking_for){ | |
try { | |
TreeMap<String, Object> map = | |
Registry.getValues(REGISTRY_ROOT_KEY.CURRENT_USER, path); | |
//get the list of all the values in this key | |
Set<String> list = map.keySet(); | |
//search through list | |
for (String value : list) { | |
if(value == name){ | |
if(map.get(value).toString == what_ur_looking_for){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
}//end search | |
return false; | |
} catch (UnsupportedEncodingException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | InterruptedException e) { | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment