Java 类com.sun.jna.platform.win32.Advapi32Util 实例源码

项目:osumer    文件:Installer.java   
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);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Get Integer registry value(REG_DWORD)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public int getIntValue(
                        String rootKey,
                        String keyPath,
                        String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetIntValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Integer. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Get Long registry value(REG_QWORD)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public long getLongValue(
                          String rootKey,
                          String keyPath,
                          String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetLongValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Long. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Get Binary registry value(REG_BINARY)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public byte[] getBinaryValue(
                              String rootKey,
                              String keyPath,
                              String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetBinaryValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Binary. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Creates path in the registry.
 *
 * Will fail if the path exists already.
 *
 * If want to create a nested path(for example "Software\\MyCompany\\MyApplication\\Configuration"),
 * it is needed to call this method for each path token(first for "Software\\MyCompany", then for "Software\\MyCompany\\MyApplication" etc)
 *
 * @param keyPath
 */
@Override
public void createPath(
                        String rootKey,
                        String keyPath ) {

    log.info("Create regestry key path: " + getDescription(rootKey, keyPath, null));

    int index = keyPath.lastIndexOf("\\");
    if (index < 1) {
        throw new RegistryOperationsException("Invalid path '" + keyPath + "'");
    }

    String keyParentPath = keyPath.substring(0, index);
    String keyName = keyPath.substring(index + 1);

    checkPathDoesNotExist(rootKey, keyPath);

    try {
        Advapi32Util.registryCreateKey(getHKey(rootKey), keyParentPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't create registry key. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Applies a String(REG_SZ) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setStringValue(
                            String rootKey,
                            String keyPath,
                            String keyName,
                            String keyValue ) {

    log.info("Set String value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetStringValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry String value '" + keyValue
                                              + "' to: "
                                              + getDescription(rootKey, keyPath, keyName),
                                              re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Applies a Integer(REG_DWORD) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setIntValue(
                         String rootKey,
                         String keyPath,
                         String keyName,
                         int keyValue ) {

    log.info("Set Intger value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetIntValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry Integer value '" + keyValue
                                              + "' to: "
                                              + getDescription(rootKey, keyPath, keyName),
                                              re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Applies a Long(REG_QWORD) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setLongValue(
                          String rootKey,
                          String keyPath,
                          String keyName,
                          long keyValue ) {

    log.info("Set Long value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetLongValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry Long value '" + keyValue + "' to: "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Applies a Binary(REG_BINARY) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setBinaryValue(
                            String rootKey,
                            String keyPath,
                            String keyName,
                            byte[] keyValue ) {

    log.info("Set Binary value '" + Arrays.toString(keyValue) + "' on: "
             + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetBinaryValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry binary value to: "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Delete a registry key
 *
 * @param keyPath
 * @param keyName
 */
@Override
public void deleteKey(
                       String rootKey,
                       String keyPath,
                       String keyName ) {

    log.info("Delete key: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registryDeleteValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't delete registry key. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目: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);
    }
}
项目:IO    文件:DeviceManager.java   
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);
    }
}
项目:IO    文件:DeviceManager.java   
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);
    }
}
项目: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()) {
                System.err.println("Browser path: " + path);
                browsers.add(path);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return browsers;
}
项目:DigitalMediaServer    文件:WinUtils.java   
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);
    }
}
项目:DigitalMediaServer    文件:WinUtils.java   
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;
}
项目:DigitalMediaServer    文件:WinUtils.java   
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;
}
项目:osumer    文件:Installer.java   
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);
    }
}
项目:WeblocOpener    文件:RegistryFixer.java   
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;
}
项目:WeblocOpener    文件:RegistryManager.java   
public static String getBrowserValue() {
    if (SETTINGS.getProperty(KEY_BROWSER) == null || SETTINGS.getProperty(KEY_BROWSER).isEmpty()) {
        try {
            String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,
                    REGISTRY_APP_PATH,
                    KEY_BROWSER);
            return value;
        } catch (Win32Exception e) {
            return ApplicationConstants.BROWSER_DEFAULT_VALUE;
        }
    } else {
        if (!SETTINGS.getProperty(KEY_BROWSER).equals(ApplicationConstants.BROWSER_DEFAULT_VALUE)) {
            return SETTINGS.getProperty(KEY_BROWSER);
        } else {
            return ApplicationConstants.BROWSER_DEFAULT_VALUE;
        }
    }
}
项目:WeblocOpener    文件:RegistryManager.java   
public static String getInstallLocationValue() throws RegistryCanNotReadInfoException {

        if (SETTINGS.getProperty(KEY_INSTALL_LOCATION) == null || SETTINGS.getProperty(KEY_INSTALL_LOCATION).isEmpty()) {
            try {
                String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,
                        REGISTRY_APP_PATH,
                        KEY_INSTALL_LOCATION);
                if (!value.endsWith(File.separator)) {
                    value = value + File.separator;
                }
                SETTINGS.setProperty(KEY_INSTALL_LOCATION, value);
                return value;
            } catch (Win32Exception e) {
                throw new RegistryCanNotReadInfoException("Can not read Installed Location value : " +
                        "HKCU\\" + REGISTRY_APP_PATH + "" +
                        KEY_INSTALL_LOCATION,
                        e);
            }
        } else return SETTINGS.getProperty(KEY_INSTALL_LOCATION);
    }
项目:WeblocOpener    文件:RegistryManager.java   
@SuppressWarnings("UnusedReturnValue")
public static String getAppNameValue() throws RegistryCanNotReadInfoException {
    if (SETTINGS.getProperty(KEY_APP_NAME) == null || SETTINGS.getProperty(KEY_APP_NAME).isEmpty()) {
        try {
            String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,
                    REGISTRY_APP_PATH,
                    KEY_APP_NAME);
            SETTINGS.setProperty(KEY_APP_NAME, value);
            return value;
        } catch (Win32Exception e) {
            throw new RegistryCanNotReadInfoException("Can not read Installed Location value : " +
                    "HKLM\\" + REGISTRY_APP_PATH + "" + KEY_APP_NAME, e);
        }
    } else return SETTINGS.getProperty(KEY_APP_NAME);

}
项目:WeblocOpener    文件:RegistryManager.java   
@SuppressWarnings("UnusedReturnValue")
public static String getURLUpdateValue() throws RegistryCanNotReadInfoException {

    if (SETTINGS.getProperty(KEY_URL_UPDATE_LINK) == null || SETTINGS.getProperty(KEY_URL_UPDATE_LINK).isEmpty()) {
        try {
            String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,
                    REGISTRY_APP_PATH,
                    KEY_URL_UPDATE_LINK);
            SETTINGS.setProperty(KEY_URL_UPDATE_LINK, value);
            return value;
        } catch (Win32Exception e) {
            throw new RegistryCanNotReadInfoException(
                    "Can not read Installed Location value : " +
                            "HKLM\\" + REGISTRY_APP_PATH + "" + KEY_URL_UPDATE_LINK, e);
        }
    } else return SETTINGS.getProperty(KEY_URL_UPDATE_LINK);

}
项目:vso-intellij    文件:WindowsStartup.java   
/**
 * 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;
    }
}
项目:me3modmanager    文件:ModManagerWindow.java   
/**
 * Shows the write permissions dialog and will execute the windows command
 * to grant permissions to the current user if accepted.
 * 
 * @param folder
 *            Folder to grant write permissions to.
 */
private void showFolderPermissionsGrantDialog(String folder) {
    String username = Advapi32Util.getUserName();
    String message = "Your user account (" + username + ") does not have write permissions to the game directory:\n";
    message += folder + "\n\n";
    message += "Mod Manager can grant write permissions to this folder to you.\nDo you want to grant permissions?";

    int result = JOptionPane.showConfirmDialog(this, message, "Write Permissions Required", JOptionPane.YES_NO_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        if (ModManager.GrantPermissionsToDirectory(folder, username)) {
            ModManager.debugLogger.writeMessage("Granted permissions to folder: " + folder);
            if (labelStatus != null) { //Can be null if permissions check is running at startup.
                labelStatus.setText("Granted write permissions to game directory");
            }
        }
    }
}
项目:me3modmanager    文件:VanillaBackupWindow.java   
/**
 * Fetches the full backup path from the registry.
 * 
 * @return Filepath from registry to full backup path. If none exists, this
 *         returns null.
 */
public static String GetFullBackupPath(boolean returnEvenIfInvalid) {
    String backupPath = null;
    try {
        backupPath = Advapi32Util.registryGetStringValue(HKEY_CURRENT_USER, VanillaUserRegistryKey, VanillaUserRegistryValue);
        File backupDir = new File(backupPath);
        if (verifyVanillaBackup(backupDir)) {
            ModManager.debugLogger.writeMessage("Found valid vanilla copy location in registry: " + backupPath);
        } else {
            ModManager.debugLogger.writeError("Found vanilla copy location in registry, but it doesn't seem to be valid, at least one of the validation checks failed");
        }
    } catch (Win32Exception e) {
        ModManager.debugLogger.writeErrorWithException("Win32Exception reading registry - assuming no backup exists yet (this is not really an error... mostly).", e);
    }

    if (backupPath != null) {
        if (new File(backupPath).exists() && new File(backupPath).isDirectory()) {
            return backupPath;
        } else if (returnEvenIfInvalid) {
            ModManager.debugLogger.writeError("returnEvenIfInvalid - returning path anyways.");
            return backupPath;
        }
    }
    return null;
}
项目:nanobot    文件:BlueStacksWinPlatform.java   
@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));
}
项目: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;
    }
}
项目: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 "";
}
项目: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 "";
}
项目: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;
}
项目: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;
    }
}
项目:osumer    文件:Installer.java   
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;
}
项目:ats-framework    文件:LocalRegistryOperations.java   
/**
 * Get String registry value(REG_SZ)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public String getStringValue(
                              String rootKey,
                              String keyPath,
                              String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);
    try {
        return Advapi32Util.registryGetStringValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type String. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
项目:ats-framework    文件:LocalRegistryOperations.java   
private void checkPathDoesNotExist(
                                    String rootKey,
                                    String keyPath ) {

    if (Advapi32Util.registryKeyExists(getHKey(rootKey), keyPath)) {
        throw new RegistryOperationsException("Registry path already exists. "
                                              + getDescription(rootKey, keyPath, null));
    }
}
项目:IO    文件:UsbWriteBlock.java   
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);
    }

}
项目:IO    文件:UsbWriteBlock.java   
/**
 * 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;

}
项目:IO    文件:UsbWriteBlock.java   
/**
 * 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);

}
项目: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;
}
项目:DigitalMediaServer    文件:WinUtils.java   
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;
    }
}