Skip to content

Commit 43c3a07

Browse files
IamLRBAHannesWell
authored andcommitted
Optimize Windows Defender exclusion script with native PowerShell
Since the script to add an exclusion to Windows Defender seems overly complex, this script replaces the complex LINQ-based exclusion check with a more idiomatic and simpler version PowerShell implementation. Fixes #2930
1 parent 477d106 commit 43c3a07

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WindowsDefenderConfigurator.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,11 @@ private static boolean isWindowsDefenderActive(IProgressMonitor monitor) throws
335335

336336
public static String createAddExclusionsPowershellCommand(String extraSeparator) {
337337
List<Path> paths = getExecutablePath();
338-
// For detailed explanations about how to read existing exclusions and how to
339-
// add new ones see:
338+
// For detailed explanations about how to add new exclusions see:
340339
// https://learn.microsoft.com/en-us/powershell/module/defender/add-mppreference?view=windowsserver2019-ps
341-
// https://learn.microsoft.com/en-us/powershell/module/defender/get-mppreference?view=windowsserver2019-ps
342-
//
343-
// For .NET's stream API called LINQ see:
344-
// https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable
345340
String excludedPaths = paths.stream().map(Path::toString).map(p -> '"' + p + '"')
346341
.collect(Collectors.joining(',' + extraSeparator));
347-
final String exclusionType = "ExclusionProcess"; //$NON-NLS-1$
348-
return String.join(';' + extraSeparator, "$exclusions=@(" + extraSeparator + excludedPaths + ')', //$NON-NLS-1$
349-
"$existingExclusions=[Collections.Generic.HashSet[String]](Get-MpPreference)." + exclusionType, //$NON-NLS-1$
350-
"if($existingExclusions -eq $null) { $existingExclusions = New-Object Collections.Generic.HashSet[String] }", //$NON-NLS-1$
351-
"$exclusionsToAdd=[Linq.Enumerable]::ToArray([Linq.Enumerable]::Where($exclusions,[Func[object,bool]]{param($ex)!$existingExclusions.Contains($ex)}))", //$NON-NLS-1$
352-
"if($exclusionsToAdd.Length -gt 0){ Add-MpPreference -" + exclusionType + " $exclusionsToAdd }"); //$NON-NLS-1$ //$NON-NLS-2$
342+
return "Add-MpPreference -ExclusionProcess " + extraSeparator + excludedPaths; //$NON-NLS-1$
353343
}
354344

355345
private static void excludeDirectoryFromScanning(IProgressMonitor monitor) throws IOException {

0 commit comments

Comments
 (0)