public static String[] getAvailableBrowsers() throws DebuggableException { try { String[] keys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH); List<String> filteredList = new ArrayList<String>(50); for (int i = 0; i < keys.length; i++) { if (!keys[i].equals(WIN_REG_INTERNET_CLIENT_KEY)) { filteredList.add(keys[i]); } } String[] out = new String[filteredList.size()]; for (int i = 0; i < out.length; i++) { out[i] = filteredList.get(i); } return out; } catch (Win32Exception e) { throw new DebuggableException(null, "(Try&catch try)", "Throw debuggable exception", "(End of function)", "Error reading registry", false, e); } }
private void checkKeyExists( String rootKey, String keyPath, String keyName ) { try { WinReg.HKEY rootHKey = getHKey(rootKey); if (!Advapi32Util.registryValueExists(rootHKey, keyPath, keyName)) { throw new RegistryOperationsException("Registry key does not exist. " + getDescription(rootKey, keyPath, keyName)); } } catch (Win32Exception e) { throw new RegistryOperationsException("Registry key path does not exist. " + getDescription(rootKey, keyPath, keyName), e); } }
private WinReg.HKEY getHKey( String key ) { if (key.equalsIgnoreCase(HKEY_CLASSES_ROOT)) { return WinReg.HKEY_CLASSES_ROOT; } else if (key.equalsIgnoreCase(HKEY_CURRENT_USER)) { return WinReg.HKEY_CURRENT_USER; } else if (key.equalsIgnoreCase(HKEY_LOCAL_MACHINE)) { return WinReg.HKEY_LOCAL_MACHINE; } else if (key.equalsIgnoreCase(HKEY_USERS)) { return WinReg.HKEY_USERS; } else if (key.equalsIgnoreCase(HKEY_CURRENT_CONFIG)) { return WinReg.HKEY_CURRENT_CONFIG; } else { throw new RegistryOperationsException("Unsupported root key '" + key + "'"); } }
private void tryUpdateVIDPID(Disk disk) { try { final String USB_DEVICES_KEY = "SYSTEM\\CurrentControlSet\\Enum\\USB"; String[] deviceKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, USB_DEVICES_KEY); for (String deviceKey : deviceKeys) { if (deviceKey.startsWith("VID")) { if (Arrays.asList( Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, USB_DEVICES_KEY + "\\" + deviceKey)) .contains(disk.physicalSerial)) { disk.VID = deviceKey.substring(4, 8); disk.PID = deviceKey.substring(13, 17); } } } } catch (Exception e) { Logging.log("Unable to retrieve VID/PID for disk " + disk.model, LogMessageType.INFO); Logging.log(e); } }
private void tryUpdateVendor(Disk disk) { try { final String USB_DEVICES_KEY = "SYSTEM\\CurrentControlSet\\Enum\\USBSTOR"; String[] deviceKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, USB_DEVICES_KEY); for (String deviceKey : deviceKeys) { if (deviceKey.startsWith("Disk")) { if (Arrays .asList(Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, USB_DEVICES_KEY + "\\" + deviceKey)) .stream().anyMatch((x) -> x.contains(disk.physicalSerial))) { int startIndex = deviceKey.indexOf("_"); if (startIndex != -1) { disk.vendorName = deviceKey.substring(startIndex + 1, deviceKey.indexOf("&", startIndex)); } } } } } catch (Exception e) { Logging.log("Unable to retrieve vendor name for disk " + disk.model, LogMessageType.DEBUG); Logging.log(e); } }
private static List<String> findBrowsersInRegistry() { // String regPath = "SOFTWARE\\Clients\\StartMenuInternet\\"; String regPath = is64bit ? "SOFTWARE\\Wow6432Node\\Clients\\StartMenuInternet\\" : "SOFTWARE\\Clients\\StartMenuInternet\\"; List<String> browsers = new ArrayList<>(); String path = null; try { for (String browserName : Advapi32Util .registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, regPath)) { path = Advapi32Util .registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, regPath + "\\" + browserName + "\\shell\\open\\command", "") .replace("\"", ""); if (path != null && new File(path).exists()) { System.err.println("Browser path: " + path); browsers.add(path); } } } catch (Exception e) { e.printStackTrace(); } return browsers; }
/** * Gets one of the root keys. * * @param key * key type * @return root key */ private static HKEY getRegistryRootKey(REGISTRY_ROOT_KEY key) { Advapi32 advapi32; HKEYByReference pHandle; HKEY handle = null; advapi32 = Advapi32.INSTANCE; pHandle = new WinReg.HKEYByReference(); if (advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WINERROR.ERROR_SUCCESS) { handle = pHandle.getValue(); } return (handle); }
protected void getVLCRegistryInfo() { String key = "SOFTWARE\\VideoLAN\\VLC"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { key = "SOFTWARE\\Wow6432Node\\VideoLAN\\VLC"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { return; } } vlcPath = Paths.get(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, key, "")); vlcVersion = new Version(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, key, "Version")); } catch (Win32Exception e) { LOGGER.debug("Could not get VLC information from Windows registry: {}", e.getMessage()); LOGGER.trace("", e); } }
protected String getAviSynthPluginsFolder() { String key = "SOFTWARE\\AviSynth"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { key = "SOFTWARE\\Wow6432Node\\AviSynth"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { return null; } } return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, key, "plugindir2_5"); } catch (Win32Exception e) { LOGGER.debug("Could not get AviSynth information from Windows registry: {}", e.getMessage()); LOGGER.trace("", e); } return null; }
protected String getKLiteFiltersFolder() { String key = "SOFTWARE\\Wow6432Node\\KLCodecPack"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { key = "SOFTWARE\\KLCodecPack"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { return null; } } return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, key, "installdir"); } catch (Win32Exception e) { LOGGER.debug("Could not get K-Lite Codec Pack information from Windows registry: {}", e.getMessage()); LOGGER.trace("", e); } return null; }
private static String getLocationFromInstallerValue() throws RegistryCanNotReadInfoException { String path; String pathValue; pathValue = getUninstallLocationForCurrentSystemArch(); try { path = WinReg.HKEY_LOCAL_MACHINE + "\\" + pathValue + "\\" + RegistryManager.KEY_INSTALL_LOCATION; System.out.println("Default installer value:" + path); path = Advapi32Util .registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, pathValue, RegistryManager.KEY_INSTALL_LOCATION); System.out.println("Default installer path: '" + path + "'"); } catch (Exception e) { final String message = "Can not read value from Windows UnInstaller: " + "HKLM\\" + pathValue; log.warn(message, e); throw new RegistryCanNotReadInfoException( message, e); } return path; }
/** * Check if registry keys exist and if the cmd file the key contains matches the latest cmd file * * @param newCmd * @return if keys exists or not */ protected static boolean doesKeyNeedUpdated(final File newCmd) throws IOException { try { final String existingKey = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, VSOI_KEY, StringUtils.EMPTY); final File existingCmd = new File(existingKey.replace("\"%1\"", "").trim()); if (!existingCmd.exists()) { logger.debug("The registry key needs updated because the old key cmd file doesn't exist."); return true; } if (existingCmd.getPath().equalsIgnoreCase(newCmd.getPath()) || FileUtils.contentEquals(existingCmd, newCmd)) { logger.debug("The registry key does not need updated because {}", existingCmd.getPath().equalsIgnoreCase(newCmd.getPath()) ? "the file paths are the same" : "the contents of the files are the same."); return false; } // use the newest cmd file so update if existing cmd file is older // TODO: version cmd file if we continually iterate on it so we chose the correct file more reliably logger.debug("The existing cmd file is {} old and the the cmd file is {} old", existingCmd.lastModified(), newCmd.lastModified()); return existingCmd.lastModified() < newCmd.lastModified() ? true : false; } catch (Win32Exception e) { // Error occurred reading the registry (possible key doesn't exist or is empty) so update just to be safe logger.debug("There was an issue reading the registry so updating the key to be safe."); return true; } }
@Override protected void doApplySize(final Size size) throws BotConfigurationException { final int width = size.x(); final int height = size.y(); final HKEYByReference key = Advapi32Util.registryGetKey(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\BlueStacks\\Guests\\Android\\FrameBuffer\\0", WinNT.KEY_READ | WinNT.KEY_WRITE); final int w1 = Advapi32Util.registryGetIntValue(key.getValue(), "WindowWidth"); final int h1 = Advapi32Util.registryGetIntValue(key.getValue(), "WindowHeight"); final int w2 = Advapi32Util.registryGetIntValue(key.getValue(), "GuestWidth"); final int h2 = Advapi32Util.registryGetIntValue(key.getValue(), "GuestHeight"); if (w1 != width || h1 != height || w2 != width || h2 != height) { Advapi32Util.registrySetIntValue(key.getValue(), "WindowWidth", width); Advapi32Util.registrySetIntValue(key.getValue(), "WindowHeight", height); Advapi32Util.registrySetIntValue(key.getValue(), "GuestWidth", width); Advapi32Util.registrySetIntValue(key.getValue(), "GuestHeight", height); Advapi32Util.registrySetIntValue(key.getValue(), "FullScreen", 0); } throw new BotConfigurationException(String.format("Please restart %s to fix resolution", BS_WINDOW_NAME)); }
/** * Returns the current APM originating from the Windows Registry. * * Note: since 2.0 SC2 outputs real-time APM instead of game-time APM, * so no conversion is performed to convert it anymore. * * <p><b>How to interpret the values in the registry?</b><br> * The digits of the result: 5 has to be subtracted from the first digit (in decimal representation), 4 has to be subtracted from the second digit, * 3 from the third etc. * If the result of a subtraction is negative, 10 has to be added. * Examples: 64 => 10 APM; 40 => 96 APM; 8768 => 3336 APM; 38 => 84 APM</p> * * @return the current APM or <code>null</code> if some error occurs */ public static Integer getApm() { try { final String apmString = Advapi32Util.registryGetStringValue( WinReg.HKEY_CURRENT_USER, "Software\\Razer\\Starcraft2", "APMValue" ); int apm = 0; for ( int idx = 0, delta = 5, digit; idx < apmString.length(); idx++, delta-- ) { digit = apmString.charAt( idx ) - '0' - delta; if ( digit < 0 ) digit += 10; apm = apm * 10 + digit; } return apm; } catch ( final Exception e ) { // Silently ignore, do not print stack trace return null; } }
private static String findMobileLibrary() { if (Platform.isWindows()) { String path; try { path = getMDPath(true); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL"); } catch (Exception ignored) { try { path = getMDPath(false); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL"); } catch (Exception ignored1) { log.info(ignored.getMessage()); return ""; } } File f = new File(path); if (f.exists()) return path; } else { if (Platform.isMac()) { return "/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice"; } } return ""; }
private static String findCoreLibrary() { String path=""; if (Platform.isWindows()) { try { path = getCPath(true); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir"); } catch (Exception ignored) { try { path = getCPath(false); path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir"); } catch (Exception ignored1) { return ""; } } path = path + "CoreFoundation.dll"; File f = new File(path); if (f.exists()) return path; } else if (Platform.isMac()) { return "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; } return ""; }
/** * Returns the osu! installation directory. * @return the directory, or null if not found */ private static File getOsuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) return null; // only works on Windows // registry location final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue); } catch (Win32Exception e) { return null; // key/value not found } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) return null; File dir = new File(m.group(1)); return (dir.isDirectory()) ? dir : null; }
public static boolean isAddedToContextMenu() { if (!Platform.isWindows()) { return false; } final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE; final String REG_CLASSES_PATH = "Software\\Classes\\"; try { if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf")) { return false; } String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf", ""); if (clsName == null) { return false; } return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + clsName + "\\shell\\ffdec"); } catch (Win32Exception ex) { return false; } }
public static String getBrowserExePath(String browserName) { String value = null; try { value = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH + "\\" + browserName + "\\shell\\open\\command", ""); } catch (Win32Exception e) { return null; } return value; }
private static void writeToKey(int value) { try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY)) { Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY); } Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY, "WriteProtect", value); } catch (IllegalArgumentException e) { Logging.log("Failed to " + (value == 0 ? "disable" : "enable") + " USB write block", LogMessageType.WARNING); Logging.log(e); } }
/** * Gets the current setting of the write block key. * @return True if write block is turned on in the registry, false otherwise. */ public static boolean getWriteBlockStatus() { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY)) { return false; } return Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY, "WriteProtect") == 1; }
/** * Sets the write block key back to what it was when ION launched. */ public static void resetWriteBlockStatus() { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY)) { return; } Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, WRITE_BLOCK_KEY, "WriteProtect", initial_status ? 1 : 0); }
private File loadOsuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) { return null; } final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue); } catch (Win32Exception ignored) { return null; } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) { return null; } File dir = new File(m.group(1)); if (dir.isDirectory()) { return dir; } return null; }
protected boolean isKerioInstalled() { try { String key = "SOFTWARE\\Kerio"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key)) { key = "SOFTWARE\\Wow6432Node\\Kerio"; return Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, key); } return true; } catch (Win32Exception e) { LOGGER.debug("Could not get Kerio information from Windows registry: {}", e.getMessage()); LOGGER.trace("", e); return false; } }
@Test public void testDoesKeyNeedUpdated_ExistingCmdOlder() throws Exception { TEST_EXE = File.createTempFile(TEST_CMD_NAME, ".cmd"); Mockito.when(FileUtils.contentEquals(TEST_EXE, mockCmdFile)).thenReturn(false); Mockito.when(mockCmdFile.getPath()).thenReturn(TEST_CMD_NAME); Mockito.when(mockCmdFile.lastModified()).thenReturn(TEST_EXE.lastModified() + 1000); Mockito.when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, WindowsStartup.VSOI_KEY, "")).thenReturn(TEST_EXE.getPath() + " \"%1\""); Assert.assertTrue(WindowsStartup.doesKeyNeedUpdated(mockCmdFile)); }
@Test public void testDoesKeyNeedUpdated_ExistingCmdNewer() throws Exception { TEST_EXE = File.createTempFile(TEST_CMD_NAME, ".cmd"); Mockito.when(FileUtils.contentEquals(TEST_EXE, mockCmdFile)).thenReturn(false); Mockito.when(mockCmdFile.getPath()).thenReturn(TEST_CMD_NAME); Mockito.when(mockCmdFile.lastModified()).thenReturn(TEST_EXE.lastModified() - 1000); Mockito.when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, WindowsStartup.VSOI_KEY, "")).thenReturn(TEST_EXE.getPath() + " \"%1\""); Assert.assertFalse(WindowsStartup.doesKeyNeedUpdated(mockCmdFile)); }
@Test public void testDoesKeyNeedUpdated_DiffFilesSameContents() throws Exception { TEST_EXE = File.createTempFile(TEST_CMD_NAME, ".cmd"); Mockito.when(FileUtils.contentEquals(TEST_EXE, mockCmdFile)).thenReturn(true); Mockito.when(mockCmdFile.getPath()).thenReturn(TEST_CMD_NAME); Mockito.when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, WindowsStartup.VSOI_KEY, "")).thenReturn(TEST_EXE.getPath() + " \"%1\""); Assert.assertFalse(WindowsStartup.doesKeyNeedUpdated(mockCmdFile)); }
/** * Attemps to read what version of .NET framework is installed and if the * release version meets the minimum ME3Explorer requirements * * @return true if satisfied, false otherwise */ public static boolean validateNETFrameworkIsInstalled() { if (!PERFORM_DOT_NET_CHECK) { NET_FRAMEWORK_IS_INSTALLED = true; return true; } String os = System.getProperty("os.name"); if (os.contains("Windows")) { int releaseNum = 0; String netFrameWork4Key = "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"; ModManager.debugLogger.writeMessage("Checking for .NET Framework 4.5 or higher registry key"); try { releaseNum = Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, netFrameWork4Key, "Release"); ModManager.debugLogger.writeMessage(".NET Framework release detected: " + releaseNum); if (releaseNum >= MIN_REQUIRED_NET_FRAMEWORK_RELNUM) { ModManager.debugLogger.writeMessage("This version (" + releaseNum + ") satisfies the current requirements (" + MIN_REQUIRED_NET_FRAMEWORK_RELNUM + ")"); NET_FRAMEWORK_IS_INSTALLED = true; return true; } else { ModManager.debugLogger.writeError("This version (" + releaseNum + ") DOES NOT satisfy the current requirements (" + MIN_REQUIRED_NET_FRAMEWORK_RELNUM + ")"); NET_FRAMEWORK_IS_INSTALLED = false; return false; } } catch (com.sun.jna.platform.win32.Win32Exception keynotfoundException) { ModManager.debugLogger.writeError(".NET Framework 4.5 registry key was not found: " + netFrameWork4Key); NET_FRAMEWORK_IS_INSTALLED = false; return false; } catch (Throwable e) { ModManager.debugLogger.writeErrorWithException(".NET Framework 4.5 detection exception:", e); NET_FRAMEWORK_IS_INSTALLED = false; return false; } } ModManager.debugLogger.writeError("This is not a windows OS. So obviously there is no registry. .NET is not installed"); NET_FRAMEWORK_IS_INSTALLED = false; return false; }
/** * Returns the current game status from the Windows Registry. * @return the current game status or <code>null</code> if some error occurs */ public static Integer getGameStatus() { try { return Advapi32Util.registryGetIntValue( WinReg.HKEY_CURRENT_USER, "Software\\Razer\\Starcraft2", "StartModule" ); } catch ( final Exception e ) { // Silently ignore, do not print stack trace return null; } }
public static String getPythonLocation() { if (Dependencies.pythonLocation != null) return Dependencies.pythonLocation; ArrayList<String> paths = new ArrayList<String>(); paths.add(null); paths.add("/"); paths.add("/usr/local/bin/"); paths.add("/usr/bin/"); if (isWindows()) { File resourcesLocation = new File(Dependencies.getResourcesLocation()); paths.add(combinePaths(resourcesLocation.getAbsolutePath(), "python")); paths.add(getPythonFromRegistry(WinReg.HKEY_CURRENT_USER)); paths.add(getPythonFromRegistry(WinReg.HKEY_LOCAL_MACHINE)); for (int i=26; i<=50; i++) { paths.add(combinePaths("\\python" + i, "pythonw")); paths.add(combinePaths("\\Python" + i, "pythonw")); } } for (String path : paths) { if (runPython(combinePaths(path, "pythonw"))) { Dependencies.pythonLocation = combinePaths(path, "pythonw"); break; } else if (runPython(combinePaths(path, "python"))) { Dependencies.pythonLocation = combinePaths(path, "python"); break; } } if (Dependencies.pythonLocation != null) { WakaTime.log.debug("Found python binary: " + Dependencies.pythonLocation); } else { WakaTime.log.warn("Could not find python binary."); } return Dependencies.pythonLocation; }
private boolean checkHotfix(final String hotfix, final String os) { if (!keyExists(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\KB" + hotfix)) { error(null, "OpenNMS requires HotFix KB" + hotfix + " to be installed for IPv6 to function properly on " + os + "." + " To install it, see the following link: http://support.microsoft.com/?kbid=" + hotfix); return false; } else { debug(null, "Found HotFix KB" + hotfix); } return true; }
private String getStringFromRegistry(final String key) { try { return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, REGISTRY_CURRENTVERSION, key); } catch (final Throwable t) { warn(t, "Unable to retrieve the value for %s\\%s", REGISTRY_CURRENTVERSION, key); return null; } }
@Nullable public static String getInstallPath() { try { return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "InstallPath"); } catch(Exception ignored) { } return null; }
@Nullable public static String getTargetVersion() { try { return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "TargetVersion"); } catch(Exception ignored) { } return null; }
public void uninstall() throws DebuggableException { File file = new File(winPath + "\\" + winFile); if (file.exists()) { file.delete(); } file = new File(winPath + "\\" + verInfoFile); if (file.exists()) { file.delete(); } file = new File(START_MENU_PATH + "\\osumer.lnk"); if (file.exists()) { file.delete(); } file = new File(START_MENU_PATH + "\\osumer (Start as Daemon).lnk"); if (file.exists()) { file.delete(); } try { final String clientRegPath = WIN_REG_CLIENTS_PATH + "\\" + WIN_REG_INTERNET_CLIENT_KEY; final String capRegPath = clientRegPath + "\\" + WIN_REG_CAP_KEY; final String shellRegPath = clientRegPath + "\\" + WIN_REG_SHELL_KEY; final String shellOpenRegPath = shellRegPath + "\\" + WIN_REG_SHELL_OPEN_KEY; // Capabilities Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_FILEASSOC_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_URLASSOC_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, capRegPath, WIN_REG_CAP_STARTMENU_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_CAP_KEY); // Shell open command Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, shellOpenRegPath, WIN_REG_SHELL_OPEN_COMMAND_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, shellRegPath, WIN_REG_SHELL_OPEN_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_SHELL_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_DEFAULTICON_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, clientRegPath, WIN_REG_INSTALLINFO_KEY); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH, WIN_REG_INTERNET_CLIENT_KEY); // Classes and Registered applications Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_REGISTEREDAPPS_PATH, WIN_REG_REGISTEREDAPPS_OSUMEREXPRESS_PARA); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY + "\\shell\\open", "command"); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY + "\\shell", "open"); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH + "\\" + WIN_REG_CLASSES_OSUMER_KEY, "shell"); Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLASSES_PATH, WIN_REG_CLASSES_OSUMER_KEY); Advapi32Util.registryDeleteValue(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_RUN_PATH, WIN_REG_RUN_OSUMERDAEMON_PARA); } catch (Win32Exception e) { e.printStackTrace(); throw new DebuggableException(null, "(Try&catch try) Writing to registry", "Throw debuggable exception", "(End of function)", "Error writing registry", false, e); } }
@Test public void testDoesKeyNeedUpdated_NoKeyExists() throws Exception { Mockito.when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, WindowsStartup.VSOI_KEY, "")).thenThrow(Win32Exception.class); Assert.assertTrue(WindowsStartup.doesKeyNeedUpdated(mockCmdFile)); }