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); } }
/** * Captures the window. * * @param hwnd The window to capture. * @param filename Name to save the output into. * @throws AWTException Robot exception. * @throws IOException IO Exception. */ public static void capture(final WinDef.HWND hwnd, final String filename) throws AWTException, IOException, Win32Exception { ensureWinApiInstances(); WinDef.RECT rect = new WinDef.RECT(); if (!user32.GetWindowRect(hwnd, rect)) { throw new Win32Exception(kernel32.GetLastError()); } Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right -rect.left, rect.bottom -rect.top); BufferedImage image = new Robot().createScreenCapture(rectangle); ImageIO.write(image, "png", new File(filename)); }
@Test(expected= Win32Exception.class) public void test_setTransparency_Throws_Exception_When_Win32_Calls_Throw_Error() throws Exception { doAnswer(invocation -> { Object[] args = invocation.getArguments(); Object reference = (Object)args[0]; reference = 1245; return 1234; }).when(element).getPropertyValue(anyInt()); IUIAutomation mocked_automation = Mockito.mock(IUIAutomation.class); UIAutomation instance = new UIAutomation(mocked_automation); AutomationWindow wndw = new AutomationWindow( new ElementBuilder(element).window(window).itemContainer(container).automation(instance)); wndw.setTransparency(100); verify(element, atLeastOnce()).getPropertyValue(anyInt()); }
/** * Authenticates the user using Windows LogonUser API */ @CheckForNull public WindowsPrincipal logonUser(String userName, String password) { checkArgument(isNotEmpty(userName), "userName is null or empty."); checkArgument(isNotEmpty(password), "password is null or empty."); LOG.debug("Authenticating user: {}", userName); WindowsPrincipal windowsPrincipal = null; IWindowsIdentity windowsIdentity = null; try { windowsIdentity = windowsAuthProvider.logonUser(userName, password); if (windowsIdentity != null) { windowsPrincipal = new WindowsPrincipal(windowsIdentity); } } catch (Win32Exception win32Exception) { LOG.debug("User {} is not authenticated : {}", userName, win32Exception.getMessage()); } finally { if (windowsIdentity != null) { windowsIdentity.dispose(); } } return windowsPrincipal; }
private void runLogonUserTest(String userName, String password, boolean isLogonUserSuccessful) { IWindowsIdentity windowsIdentity = null; Win32Exception win32Exception = mock(Win32Exception.class); if (isLogonUserSuccessful) { windowsIdentity = mock(IWindowsIdentity.class); Mockito.when(windowsIdentity.getFqn()).thenReturn(userName); Mockito.when(windowsIdentity.getGroups()).thenReturn(new IWindowsAccount[0]); Mockito.when(windowsAuthProvider.logonUser(userName, password)).thenReturn(windowsIdentity); } else { Mockito.when(windowsAuthProvider.logonUser(userName, password)).thenThrow(win32Exception); } WindowsPrincipal windowsPrincipal = authenticationHelper.logonUser(userName, password); if (isLogonUserSuccessful) { assertThat(windowsPrincipal.getName()).isEqualTo(windowsIdentity.getFqn()); Mockito.verify(windowsIdentity, Mockito.times(1)).dispose(); Mockito.verify(win32Exception, Mockito.times(0)).getMessage(); } else { assertThat(windowsPrincipal).isNull(); Mockito.verify(win32Exception, Mockito.times(1)).getMessage(); } Mockito.verify(windowsAuthProvider, Mockito.times(1)).logonUser(userName, password); }
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; }
/** * Retrieves the id of the process that belongs to the given exe-file name. * * @param szExeFile * Name of the exe-File. * @return The id of the process that belongs to the given exe-file name or * <tt>0</tt> (zero) if not found. */ public static int getProcessIdBySzExeFile(final String szExeFile) { try { final Iterator<Process> processes = Kernel32Util.getProcessList().iterator(); while (processes.hasNext()) { final Process process = processes.next(); if (process.getSzExeFile().equalsIgnoreCase(szExeFile)) { return process.getPid(); } } } catch (final Win32Exception e) { // Just catch the exception and return an error code } return 0; }
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; } } }
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); }
@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); }
@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); }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * Sets transparency of the window. * @param alpha 0..255 alpha attribute. * @throws Win32Exception WIN32 call has failed. * @throws AutomationException Something is wrong in automation. */ public void setTransparency(int alpha) throws Win32Exception, AutomationException { WinDef.HWND hwnd = this.getNativeWindowHandle(); if (user32.SetWindowLong(hwnd, User32.GWL_EXSTYLE, User32.WS_EX_LAYERED) == 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } if (!user32.SetLayeredWindowAttributes(hwnd, 0, (byte)alpha, User32.LWA_ALPHA)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } }
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; }
@CheckForNull private IWindowsAccount getWindowsAccount(String userName) { IWindowsAccount windowsAccount = null; try { windowsAccount = windowsAuthProvider.lookupAccount(userName); } catch (Win32Exception win32Exception) { LOG.debug("User {} is not found: {}", userName, win32Exception.getMessage()); } return windowsAccount; }
@Test public void getUserDetailsFromUserNameWindowsAccountNullTest() { String userName = "User"; String domainName = "Domain"; String userNameWithDomain = getAccountNameWithDomain(domainName, "\\", userName); Win32Exception win32Exception = mock(Win32Exception.class); IWindowsAccount windowsAccount = getIWindowsAccount(domainName, userName); assertThat(authenticationHelper.getUserDetails(userNameWithDomain)).isNull(); Mockito.when(windowsAuthProvider.lookupAccount(userNameWithDomain)).thenThrow(win32Exception); assertThat(authenticationHelper.getUserDetails(userNameWithDomain)).isNull(); Mockito.verify(win32Exception, Mockito.times(1)).getMessage(); }
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; } }
@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; }
@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; }
/** * Gets a list of currently active processes by creating a snapshot. * * @return List of currently active processes * @throws Win32Exception * If the operation was not successful */ public static ProcessList getProcessList() throws Win32Exception { final ProcessList plist = new ProcessList(); final List<PROCESSENTRY32> list = new LinkedList<>(); final HANDLE hProcessSnap = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new DWORD(0)); PROCESSENTRY32 pe32 = new PROCESSENTRY32(); if (!Kernel32.INSTANCE.Process32First(hProcessSnap, pe32)) { throw new Win32Exception(Native.getLastError()); } do { if (pe32.th32ProcessID.intValue() != 0) { list.add(pe32); } pe32 = new PROCESSENTRY32(); } while (Kernel32.INSTANCE.Process32Next(hProcessSnap, pe32)); for (final PROCESSENTRY32 pe : list) { plist.add(new Process(pe)); } Kernel32.INSTANCE.CloseHandle(hProcessSnap); final List<DesktopWindow> windows = WindowUtils.getAllWindows(false); final IntByReference lpdwProcessId = new IntByReference(); int pid = 0; for (final DesktopWindow window : windows) { User32.INSTANCE.GetWindowThreadProcessId(window.getHWND(), lpdwProcessId); pid = lpdwProcessId.getValue(); plist.add(pid, window.getHWND()); } return plist; }
/** * Whether the given process is a 64-bit application or not. A 32-bit * application that runs in the WoW64 environment is not considered as * 64-bit application, since they are restricted to the 32-bit memory space. * * @param hProcess * Handle to the process in question * @return <tt>True</tt> if the given process is a 64-bit application, * <tt>false</tt> otherwise. * @throws Win32Exception * If the operation was not successful */ public static boolean is64Bit(final HANDLE hProcess) throws Win32Exception { if (System.getenv(SystemProperties.PRC_ARCH) == Masks.PRC_ARCH_32BIT) { return false; } final IntByReference isWow64 = new IntByReference(); final boolean success = Kernel32.INSTANCE.IsWow64Process(hProcess, isWow64); if (!success) { throw new Win32Exception(Native.getLastError()); } return isWow64.getValue() == 0; }
public static String getAppVersionValue() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_CURRENT_VERSION) == null || SETTINGS.getProperty(KEY_CURRENT_VERSION).isEmpty()) { try { String result = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY, REGISTRY_APP_PATH, KEY_CURRENT_VERSION); SETTINGS.setProperty(KEY_CURRENT_VERSION, result); return result; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not get app version value", e); } } else return SETTINGS.getProperty(KEY_CURRENT_VERSION); }
public static boolean isAutoUpdateActive() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_AUTO_UPDATE) == null || SETTINGS.getProperty(KEY_AUTO_UPDATE).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY, REGISTRY_APP_PATH, KEY_AUTO_UPDATE); boolean result = Boolean.parseBoolean(value); //prevents SETTINGS.setProperty(KEY_AUTO_UPDATE, Boolean.toString(result)); return result; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not read " + RegistryManager.KEY_AUTO_UPDATE + " value", e); } } else return Boolean.parseBoolean(SETTINGS.getProperty(KEY_AUTO_UPDATE)); }
public static void createRegistryEntry(String path, String valueName, String value) throws RegistryCanNotWriteInfoException { try { SETTINGS.setProperty(valueName, value); Advapi32Util.registrySetStringValue(APP_ROOT_HKEY, path, valueName, value); } catch (Win32Exception e) { throw new RegistryCanNotWriteInfoException("Can not create entry at: " + APP_ROOT_HKEY + "\\" + path + valueName + " With value [" + value + "]", e); } }
public static void createRootRegistryFolder(String path) throws RegistryCanNotWriteInfoException { if (!Advapi32Util.registryKeyExists(APP_ROOT_HKEY, path)) { try { Advapi32Util.registryCreateKey(APP_ROOT_HKEY, path); } catch (Win32Exception e) { throw new RegistryCanNotWriteInfoException("Can not create root folder on registry.", e); } } }
String getToken( final CtxtHandle continueCtx, final SecBufferDesc continueToken, final String targetName) { final IntByReference attr = new IntByReference(); final SecBufferDesc token = new SecBufferDesc( Sspi.SECBUFFER_TOKEN, Sspi.MAX_TOKEN_SIZE); sspiContext = new 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.getBytes()); }
@Override String getToken(final CtxtHandle continueCtx, final SecBufferDesc continueToken, final String targetName) { dispose(); /* We will rather throw SEC_E_TARGET_UNKNOWN because SEC_E_DOWNGRADE_DETECTED is not * available on Windows XP and this unit test always fails. */ throw new Win32Exception(WinError.SEC_E_TARGET_UNKNOWN); }
@Override public int getBrightness() throws Win32Exception { DWORDByReference minBrightness = new DWORDByReference(); DWORDByReference curBrightness = new DWORDByReference(); DWORDByReference maxBrightness = new DWORDByReference(); check(Dxva2.INSTANCE.GetMonitorBrightness(handle, minBrightness, curBrightness, maxBrightness)); // return curBright; return curBrightness.getValue().intValue(); }
private void check(BOOL retVal) { if (!retVal.booleanValue()) { int err = Kernel32.INSTANCE.GetLastError(); if (err != 0) throw new Win32Exception(err); } }
private CredHandle acquireCredentialsHandle() { CredHandle handle = new CredHandle(); int rc = Secur32.INSTANCE.AcquireCredentialsHandle(null, "NTLM", SECPKG_CRED_OUTBOUND, null, null, null, null, handle, new TimeStamp()); if (SEC_E_OK != rc) { throw new Win32Exception(rc); } return handle; }
@Test(expected = Win32Exception.class) public void test_setTransparency_Throws_Exception_When_SetWindowLong_Returns_Error() throws Exception { doAnswer(invocation -> 0).when(user32).SetWindowLong(any(), anyInt(), anyInt()); doAnswer(invocation -> true).when(user32).SetLayeredWindowAttributes(any(), anyInt(), anyByte(), anyInt()); doAnswer(invocation -> { Object[] args = invocation.getArguments(); Object reference = (Object)args[0]; reference = 1245; return 1234; }).when(element).getPropertyValue(anyInt()); AutomationWindow wndw = new AutomationWindow( new ElementBuilder(element).window(window).itemContainer(container).user32(user32)); wndw.setTransparency(100); verify(element, atLeastOnce()).getPropertyValue(anyInt()); }