|
30 | 30 | import java.util.concurrent.Future; |
31 | 31 | import java.util.stream.Collectors; |
32 | 32 | import org.eclipse.core.runtime.CoreException; |
| 33 | +import org.eclipse.core.runtime.ILog; |
33 | 34 | import org.eclipse.core.runtime.IProduct; |
34 | 35 | import org.eclipse.core.runtime.IProgressMonitor; |
35 | 36 | import org.eclipse.core.runtime.OperationCanceledException; |
@@ -149,8 +150,8 @@ private enum HandlingOption { |
149 | 150 | * Windows Defender is inactive and null if the process was aborted. |
150 | 151 | */ |
151 | 152 | private static Boolean runExclusionCheck(IProgressMonitor m, Optional<Path> installLocation) throws CoreException { |
152 | | - SubMonitor monitor = SubMonitor.convert(m, 3); |
153 | | - if (!isWindowsDefenderActive(monitor.split(1))) { |
| 153 | + SubMonitor monitor = SubMonitor.convert(m, 4); |
| 154 | + if (!isWindowsDefenderServiceRunning(monitor.split(1)) || !isWindowsDefenderActive(monitor.split(1))) { |
154 | 155 | return Boolean.FALSE; |
155 | 156 | } |
156 | 157 | Display display = Display.getDefault(); |
@@ -275,6 +276,19 @@ private static List<Path> getExecutablePath() { |
275 | 276 | return List.of(Path.of(eclipseLauncher)); |
276 | 277 | } |
277 | 278 |
|
| 279 | + private static boolean isWindowsDefenderServiceRunning(IProgressMonitor monitor) { |
| 280 | + // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.4 |
| 281 | + // https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicecontrollerstatus?view=dotnet-plat-ext-8.0 |
| 282 | + try { |
| 283 | + List<String> result = runProcess(List.of("powershell.exe", "-Command", "(Get-Service 'WinDefend').Status"), //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ |
| 284 | + monitor); |
| 285 | + return result.size() == 1 && "Running".equalsIgnoreCase(result.get(0)); //$NON-NLS-1$ |
| 286 | + } catch (IOException e) { |
| 287 | + ILog.get().error("Failed to obtain 'WinDefend' service state", e); //$NON-NLS-1$ |
| 288 | + return false; |
| 289 | + } |
| 290 | + } |
| 291 | + |
278 | 292 | private static boolean isWindowsDefenderActive(IProgressMonitor monitor) throws CoreException { |
279 | 293 | // https://learn.microsoft.com/en-us/powershell/module/defender/get-mpcomputerstatus |
280 | 294 | List<String> command = List.of("powershell.exe", "-Command", "(Get-MpComputerStatus).AMRunningMode"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ |
|
0 commit comments