本文整理汇总了Java中com.sun.jna.platform.win32.Win32Exception类的典型用法代码示例。如果您正苦于以下问题:Java Win32Exception类的具体用法?Java Win32Exception怎么用?Java Win32Exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Win32Exception类属于com.sun.jna.platform.win32包,在下文中一共展示了Win32Exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableBrowsers
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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);
}
}
示例2: checkKeyExists
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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);
}
}
示例3: capture
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
/**
* 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));
}
示例4: test_setTransparency_Throws_Exception_When_Win32_Calls_Throw_Error
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
@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());
}
示例5: logonUser
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
/**
* 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;
}
示例6: runLogonUserTest
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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);
}
开发者ID:SonarQubeCommunity,项目名称:sonar-activedirectory,代码行数:26,代码来源:WindowsAuthenticationHelperTest.java
示例7: getVLCRegistryInfo
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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);
}
}
示例8: getAviSynthPluginsFolder
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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;
}
示例9: getKLiteFiltersFolder
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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;
}
示例10: getProcessIdBySzExeFile
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
/**
* 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;
}
示例11: getBrowserValue
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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;
}
}
}
示例12: getInstallLocationValue
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
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);
}
示例13: getAppNameValue
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
@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);
}
示例14: getURLUpdateValue
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
@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);
}
示例15: doesKeyNeedUpdated
import com.sun.jna.platform.win32.Win32Exception; //导入依赖的package包/类
/**
* 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;
}
}