mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Make av registry check more robust
This commit is contained in:
parent
a4eef3fdf7
commit
f660c20188
2 changed files with 14 additions and 6 deletions
|
@ -28,8 +28,7 @@ public class AppAvCheck {
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
var bitdefender = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir");
|
||||
return bitdefender.isPresent();
|
||||
return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir");
|
||||
}
|
||||
},
|
||||
MALWAREBYTES("Malwarebytes") {
|
||||
|
@ -40,8 +39,7 @@ public class AppAvCheck {
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
var reg = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id");
|
||||
return reg.isPresent();
|
||||
return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id");
|
||||
}
|
||||
},
|
||||
MCAFEE("McAfee") {
|
||||
|
@ -52,8 +50,7 @@ public class AppAvCheck {
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
var mcafee = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\McAfee", "mi");
|
||||
return mcafee.isPresent();
|
||||
return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\McAfee", "mi");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,17 @@ public class WindowsRegistry {
|
|||
public static final int HKEY_CURRENT_USER = 0x80000001;
|
||||
public static final int HKEY_LOCAL_MACHINE = 0x80000002;
|
||||
|
||||
public static boolean exists(int hkey, String key, String valueName) {
|
||||
// This can fail even with errors in case the jna native library extraction fails
|
||||
try {
|
||||
return Advapi32Util.registryValueExists(
|
||||
hkey == HKEY_LOCAL_MACHINE ? WinReg.HKEY_LOCAL_MACHINE : WinReg.HKEY_CURRENT_USER, key, valueName);
|
||||
} catch (Throwable t) {
|
||||
ErrorEvent.fromThrowable(t).handle();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<String> readString(int hkey, String key) {
|
||||
return readString(hkey, key, null);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue