|
39 | 39 |
|
40 | 40 | import com.sun.jna.Platform; |
41 | 41 | import com.sun.jna.platform.win32.Advapi32Util; |
| 42 | +import com.sun.jna.platform.win32.Win32Exception; |
42 | 43 |
|
43 | 44 | /** |
44 | 45 | * This is a {@link UsbSerialDiscovery} implementation component for Windows. |
@@ -141,7 +142,13 @@ public Set<UsbSerialDeviceInformation> scanAllUsbDevicesInformation() { |
141 | 142 | } |
142 | 143 |
|
143 | 144 | Set<UsbSerialDeviceInformation> result = new HashSet<>(); |
144 | | - String[] deviceKeys = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, USB_REGISTRY_ROOT); |
| 145 | + String[] deviceKeys; |
| 146 | + try { |
| 147 | + deviceKeys = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, USB_REGISTRY_ROOT); |
| 148 | + } catch (Win32Exception e) { |
| 149 | + logger.debug("registryGetKeys failed for {}", USB_REGISTRY_ROOT, e); |
| 150 | + return result; |
| 151 | + } |
145 | 152 |
|
146 | 153 | for (String deviceKey : deviceKeys) { |
147 | 154 | logger.trace("{}", deviceKey); |
@@ -171,14 +178,26 @@ public Set<UsbSerialDeviceInformation> scanAllUsbDevicesInformation() { |
171 | 178 | String serialNumber = ids.length > 2 ? ids[2] : null; |
172 | 179 |
|
173 | 180 | String devicePath = USB_REGISTRY_ROOT + BACKSLASH + deviceKey; |
174 | | - String[] interfaceNames = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, devicePath); |
| 181 | + String[] interfaceNames; |
| 182 | + try { |
| 183 | + interfaceNames = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, devicePath); |
| 184 | + } catch (Win32Exception e) { |
| 185 | + logger.debug("registryGetKeys failed for {}", devicePath, e); |
| 186 | + continue; |
| 187 | + } |
175 | 188 |
|
176 | 189 | int interfaceId = 0; |
177 | 190 | for (String interfaceName : interfaceNames) { |
178 | 191 | logger.trace(" interfaceId:{}, interfaceName:{}", interfaceId, interfaceName); |
179 | 192 |
|
180 | 193 | String interfacePath = devicePath + BACKSLASH + interfaceName; |
181 | | - TreeMap<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, interfacePath); |
| 194 | + TreeMap<String, Object> values; |
| 195 | + try { |
| 196 | + values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, interfacePath); |
| 197 | + } catch (Win32Exception e) { |
| 198 | + logger.debug("registryGetValues failed for {}", interfacePath, e); |
| 199 | + continue; |
| 200 | + } |
182 | 201 |
|
183 | 202 | if (logger.isTraceEnabled()) { |
184 | 203 | for (Entry<String, Object> value : values.entrySet()) { |
@@ -211,15 +230,27 @@ public Set<UsbSerialDeviceInformation> scanAllUsbDevicesInformation() { |
211 | 230 | } |
212 | 231 |
|
213 | 232 | String serialPort = ""; |
214 | | - String[] interfaceSubKeys = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, interfacePath); |
| 233 | + String[] interfaceSubKeys; |
| 234 | + try { |
| 235 | + interfaceSubKeys = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, interfacePath); |
| 236 | + } catch (Win32Exception e) { |
| 237 | + logger.debug("registryGetKeys failed for {}", interfacePath, e); |
| 238 | + continue; |
| 239 | + } |
215 | 240 |
|
216 | 241 | for (String interfaceSubKey : interfaceSubKeys) { |
217 | 242 | if (!KEY_DEVICE_PARAMETERS.equals(interfaceSubKey)) { |
218 | 243 | continue; |
219 | 244 | } |
220 | 245 | String deviceParametersPath = interfacePath + BACKSLASH + interfaceSubKey; |
221 | | - TreeMap<String, Object> deviceParameterValues = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, |
222 | | - deviceParametersPath); |
| 246 | + TreeMap<String, Object> deviceParameterValues; |
| 247 | + try { |
| 248 | + deviceParameterValues = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, |
| 249 | + deviceParametersPath); |
| 250 | + } catch (Win32Exception e) { |
| 251 | + logger.debug("registryGetValues failed for {}", deviceParametersPath, e); |
| 252 | + continue; |
| 253 | + } |
223 | 254 | Object serialPortValue = deviceParameterValues.get(KEY_SERIAL_PORT); |
224 | 255 | if (serialPortValue instanceof String serialPortString) { |
225 | 256 | serialPort = serialPortString; |
|
0 commit comments