com.sun.jna.platform.win32.Win32Exception Java Examples
The following examples show how to use
com.sun.jna.platform.win32.Win32Exception.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalRegistryOperations.java From ats-framework with Apache License 2.0 | 6 votes |
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); } }
Example #2
Source File: Options.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example #3
Source File: ContextMenuTools.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
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; } }
Example #4
Source File: BackportWindowsNegotiateScheme.java From cyberduck with GNU General Public License v3.0 | 5 votes |
String getToken( final Sspi.CtxtHandle continueCtx, final Sspi.SecBufferDesc continueToken, final String targetName) { final IntByReference attr = new IntByReference(); final ManagedSecBufferDesc token = new ManagedSecBufferDesc( Sspi.SECBUFFER_TOKEN, Sspi.MAX_TOKEN_SIZE); sspiContext = new Sspi.CtxtHandle(); final int rc = Secur32.INSTANCE.InitializeSecurityContext(clientCred, continueCtx, targetName, Sspi.ISC_REQ_DELEGATE | Sspi.ISC_REQ_MUTUAL_AUTH, 0, Sspi.SECURITY_NATIVE_DREP, continueToken, 0, sspiContext, token, attr, null); switch(rc) { case WinError.SEC_I_CONTINUE_NEEDED: continueNeeded = true; break; case WinError.SEC_E_OK: dispose(); // Don't keep the context continueNeeded = false; break; default: dispose(); throw new Win32Exception(rc); } return Base64.encodeBase64String(token.getBuffer(0).getBytes()); }
Example #5
Source File: Configuration.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
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; }
Example #6
Source File: Win32Process.java From Java-Memory-Manipulation with Apache License 2.0 | 5 votes |
@Override public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) { if (Kernel32.ReadProcessMemory(pointer(), address, buffer, size, 0) == 0) { throw new Win32Exception(Native.getLastError()); } return buffer; }
Example #7
Source File: Win32Process.java From Java-Memory-Manipulation with Apache License 2.0 | 5 votes |
@Override public Process write(Pointer address, MemoryBuffer buffer) { if (Kernel32.WriteProcessMemory(pointer(), address, buffer, buffer.size(), 0) == 0) { throw new Win32Exception(Native.getLastError()); } return this; }
Example #8
Source File: Win32Process.java From Java-Memory-Manipulation with Apache License 2.0 | 5 votes |
@Override public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) { if (Kernel32.ReadProcessMemory(pointer(), address, buffer, size, 0) == 0) { throw new Win32Exception(Native.getLastError()); } return buffer; }
Example #9
Source File: Win32Process.java From Java-Memory-Manipulation with Apache License 2.0 | 5 votes |
@Override public Process write(Pointer address, MemoryBuffer buffer) { if (Kernel32.WriteProcessMemory(pointer(), address, buffer, buffer.size(), 0) == 0) { throw new Win32Exception(Native.getLastError()); } return this; }
Example #10
Source File: JnaWinRegistry.java From p4ic4idea with Apache License 2.0 | 5 votes |
@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; } }
Example #11
Source File: HostnameUtilsWin.java From netbeans with Apache License 2.0 | 3 votes |
/** * Gets the computer name. * * <p>This is the also known as the NetBIOS name, although NetBIOS is * hardly used anymore. It is the same value as can be seen from the * {@code COMPUTERNAME} environment variable. * * <p> * Windows API equivalent: {@code GetComputerName()} function from * {@code Kernel32} library. * * @return computer name * @throws NativeException if there was an error executing the * system call. */ public static String getComputerName() throws NativeException { try { return Kernel32Util.getComputerName(); } catch (Win32Exception ex) { LOGGER.log(Level.FINE, "Kernel32.GetComputerName error : {0}", ex.getHR().intValue()); String env = System.getenv("COMPUTERNAME"); if (env != null) { return env; } throw new NativeException(ex.getHR().intValue(), "error calling 'GetComputerName()' function"); } }