Skip to content

Commit e630919

Browse files
committed
Handle enabled tamper-protection in Win-Defender Autofix startup check
Fixes #1709
1 parent a768a39 commit e630919

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private enum HandlingOption {
150150
* Windows Defender is inactive and null if the process was aborted.
151151
*/
152152
private static Boolean runExclusionCheck(IProgressMonitor m, Optional<Path> installLocation) throws CoreException {
153-
SubMonitor monitor = SubMonitor.convert(m, 4);
153+
SubMonitor monitor = SubMonitor.convert(m, 5);
154154
if (!isWindowsDefenderServiceRunning(monitor.split(1)) || !isWindowsDefenderActive(monitor.split(1))) {
155155
return Boolean.FALSE;
156156
}
@@ -159,6 +159,12 @@ private static Boolean runExclusionCheck(IProgressMonitor m, Optional<Path> inst
159159
if (decision != null) {
160160
switch (decision) {
161161
case EXECUTE_EXCLUSION -> {
162+
if (isExclusionTamperProtectionEnabled(monitor.split(1))) {
163+
display.syncExec(() -> MessageDialog.openError(null, "Exclusion failed", //$NON-NLS-1$
164+
bindProductName(WorkbenchMessages.WindowsDefenderConfigurator_exclusionFailed_Protected)));
165+
savePreference(ConfigurationScope.INSTANCE, PREFERENCE_STARTUP_CHECK_SKIP, "true"); //$NON-NLS-1$
166+
return null; // Consider selection as 'aborted' and don't show the dialog again on startup
167+
}
162168
try {
163169
WindowsDefenderConfigurator.excludeDirectoryFromScanning(monitor.split(2));
164170
savePreference(ConfigurationScope.INSTANCE, PREFERENCE_EXCLUDED_INSTALLATION_PATH,
@@ -276,6 +282,18 @@ private static List<Path> getExecutablePath() {
276282
return List.of(Path.of(eclipseLauncher));
277283
}
278284

285+
private static boolean isExclusionTamperProtectionEnabled(IProgressMonitor monitor) {
286+
// https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/manage-tamper-protection-intune?view=o365-worldwide#how-to-determine-whether-antivirus-exclusions-are-tamper-protected-on-a-windows-device
287+
try { // Query the Windows Registry
288+
List<String> result = runProcess(List.of("powershell.exe", "-Command", //$NON-NLS-1$//$NON-NLS-2$
289+
"Get-ItemPropertyValue -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows Defender\\Features' -Name 'TPExclusions'"), //$NON-NLS-1$
290+
monitor);
291+
return result.size() == 1 && "1".equals(result.get(0)); //$NON-NLS-1$
292+
} catch (IOException e) {
293+
return false;
294+
}
295+
}
296+
279297
private static boolean isWindowsDefenderServiceRunning(IProgressMonitor monitor) {
280298
// https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.4
281299
// https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicecontrollerstatus?view=dotnet-plat-ext-8.0

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ public class WorkbenchMessages extends NLS {
614614
public static String WindowsDefenderConfigurator_statusInactive;
615615
public static String WindowsDefenderConfigurator_statusCheckFailed;
616616
public static String WindowsDefenderConfigurator_exclusionFailed;
617+
public static String WindowsDefenderConfigurator_exclusionFailed_Protected;
617618

618619
// ==============================================================================
619620
// Editor Framework

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ WindowsDefenderConfigurator_runExclusionFromPreferenceButtonLabel=Run exclusion
586586
WindowsDefenderConfigurator_statusInactive=Windows Defender is not active on this computer.
587587
WindowsDefenderConfigurator_statusCheckFailed=Failed to retrieve Windows Defender status.
588588
WindowsDefenderConfigurator_exclusionFailed=Failed to exclude {0} from being scanned by Windows Defender.
589+
WindowsDefenderConfigurator_exclusionFailed_Protected=Cannot exclude {0} from being scanned by Windows Defender.\nTamper protection for antivirus exclusions is enabled.
589590

590591
# ==============================================================================
591592
# Editor Framework

0 commit comments

Comments
 (0)