类com.sun.jna.platform.win32.WinReg源码实例Demo

下面列出了怎么用com.sun.jna.platform.win32.WinReg的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ats-framework   文件: LocalRegistryOperations.java
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);
    }
}
 
源代码2 项目: ats-framework   文件: LocalRegistryOperations.java
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 + "'");
    }
}
 
@Override
public Map<String, String> readProperties() {
	if (!IS_WINDOWS) {
		return null;
	}
	try {
		// Check if key exists
		if (!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, CONFIG_KEY)) {
			return null;
		}
		// Read values from registry
		TreeMap<String, Object> map = Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, CONFIG_KEY);
		Map<String, String> values = new HashMap<>();
		map.forEach((String k, Object oV) -> {
					String v = Objects.toString(oV, null);
					values.put(k.trim(), v != null ? v.trim() : null);
				}
		);
		LogService.getRoot().fine(() -> String.format("Successfully enforced %d settings from the Windows registry.", values.size()));
		return values;
	} catch (Throwable e) {
		LogService.getRoot().log(Level.WARNING, "Failed to access the Windows registry.", e);
		return null;
	}
}
 
源代码4 项目: sc2gears   文件: Sc2RegMonitor.java
/**
 * 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;
	}
}
 
源代码5 项目: APICloud-Studio   文件: LibraryFinder.java
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 "";
}
 
源代码6 项目: APICloud-Studio   文件: LibraryFinder.java
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 "";
}
 
源代码7 项目: opsu   文件: Options.java
/**
 * 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;
}
 
源代码8 项目: jpexs-decompiler   文件: ContextMenuTools.java
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;
    }
}
 
源代码9 项目: SWET   文件: OSUtils.java
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()) {
				String browser = path.replaceAll("\\\\", "/")
						.replaceAll("^(?:.+)/([^/]+)(.exe)$", "$1$2");
				if (debug)
					err.println("Found browser: " + browser);
				browsers.add(path.toString());
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return browsers;
}
 
源代码10 项目: SWET   文件: OSUtils.java
public static int getAdvancedOptionsZoom() {
	int value = -1;
	try {
		value = Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE,
				"SOFTWARE\\Microsoft\\Internet Explorer\\AdvancedOptions\\ACCESSIBILITY\\ZOOMLEVEL",
				"CheckedValue");
	} catch (Exception e) {
		e.printStackTrace();
	}
	return value;
}
 
源代码11 项目: opsu-dance   文件: Configuration.java
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;
}
 
源代码12 项目: sc2gears   文件: Sc2RegMonitor.java
/**
 * 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;
	}
}
 
源代码13 项目: p4ic4idea   文件: JnaWinRegistry.java
@Nullable
public static String readString(WinReg.HKEY hkey, String key, String valueName) {
    if (! isAvailable()) {
        return null;
    }
    try {
        return Advapi32Util.registryGetStringValue(hkey, key, valueName);
    } catch (Win32Exception e) {
        return null;
    }
}
 
源代码14 项目: APICloud-Studio   文件: LibraryFinder.java
private static boolean loadPath() {
	String mdPath;
	String cfpath;
	if (Platform.isWindows()) {
		try {

			mdPath = getMDPath(true);
			mdPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, mdPath, "iTunesMobileDeviceDLL");
			
			cfpath = getCPath(true);
			cfpath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, cfpath, "InstallDir");

			ANBActivator
			.getDefault()
			.getLog()
			.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
					"loadPath() mdpath = "+mdPath+ " cfpath = "+cfpath, null));

		} catch (Throwable ignored) {
			try {
				mdPath = getMDPath(false);
				mdPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, mdPath, "iTunesMobileDeviceDLL");
				
				cfpath = getCPath(false);
				cfpath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, cfpath, "InstallDir");

			} catch (Throwable ignored1) {
				ignored.printStackTrace();
				ANBActivator
				.getDefault()
				.getLog()
				.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
						"windows registry path not exist", null));
				return false;
			}
		}
		File fMd = new File(mdPath);
		if (!(fMd.exists())) {
			ANBActivator
			.getDefault()
			.getLog()
			.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
					"File path not exist", null));
			return false;
		}			
		String pathEnvVar = System.getenv("Path");
		pathEnvVar = pathEnvVar +   cfpath  + ";" + fMd.getParent() ;
		
		Environment.setEnv("Path", pathEnvVar);
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"Environment.setEnv pathEnvVar = " + pathEnvVar, null));
		
         String sqlite3 = cfpath + "/SQLite3.dll";
         File fsql = new File(sqlite3);
         if (fsql.exists())
           System.load(cfpath + "/SQLite3.dll");
         
         String cfnetwork = cfpath + "/CFNetwork.dll";
         File fcfn = new File(cfnetwork);
         if (fcfn.exists())
           System.load(cfpath + "/CFNetwork.dll");
    }
    return true;
}
 
源代码15 项目: jpexs-decompiler   文件: ContextMenuTools.java
private static void registryDeleteKey(WinReg.HKEY hKey, String keyName) {
    boolean exists = Advapi32Util.registryKeyExists(hKey, keyName);
    if (exists) {
        Advapi32Util.registryDeleteKey(hKey, keyName);
    }
}
 
源代码16 项目: jpexs-decompiler   文件: ContextMenuTools.java
private static void registryDeleteValue(WinReg.HKEY root, String keyPath, String valueName) {
    boolean exists = Advapi32Util.registryValueExists(root, keyPath, valueName);
    if (exists) {
        Advapi32Util.registryDeleteValue(root, keyPath, valueName);
    }
}
 
源代码17 项目: jpexs-decompiler   文件: Main.java
public static void initLang() {
    if (!Configuration.locale.hasValue()) {
        if (Platform.isWindows()) {
            //Load from Installer
            String uninstKey = "{E618D276-6596-41F4-8A98-447D442A77DB}_is1";
            uninstKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + uninstKey;
            try {
                if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey)) {
                    if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language")) {
                        String installedLoc = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language");
                        int lcid = Integer.parseInt(installedLoc);
                        char[] buf = new char[9];
                        int cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO639LANGNAME, buf, 9);
                        String langCode = new String(buf, 0, cnt).trim().toLowerCase();

                        cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO3166CTRYNAME, buf, 9);
                        String countryCode = new String(buf, 0, cnt).trim().toLowerCase();

                        List<String> langs = Arrays.asList(SelectLanguageDialog.getAvailableLanguages());
                        for (int i = 0; i < langs.size(); i++) {
                            langs.set(i, langs.get(i).toLowerCase());
                        }

                        String selectedLang = null;

                        if (langs.contains(langCode + "-" + countryCode)) {
                            selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode + "-" + countryCode)];
                        } else if (langs.contains(langCode)) {
                            selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode)];
                        }
                        if (selectedLang != null) {
                            Configuration.locale.set(selectedLang);
                        }
                    }
                }
            } catch (Exception ex) {
                //ignore
            }
        }
    }
    Locale.setDefault(Locale.forLanguageTag(Configuration.locale.get()));
    AppStrings.updateLanguage();

    Helper.decompilationErrorAdd = AppStrings.translate(Configuration.autoDeobfuscate.get() ? "deobfuscation.comment.failed" : "deobfuscation.comment.tryenable");
}
 
 类所在包
 类方法
 同包方法