diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 8d48a398..17f63179 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -289,24 +289,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG") @@ -8444,7 +8437,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) { diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 4fcfc9ac..5025ad0a 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -271,24 +271,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) @@ -6877,7 +6870,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) { diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 79d593e4..ef8b85bc 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -271,24 +271,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) @@ -7498,7 +7491,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) { diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index b482c4d4..a7f73f51 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -289,24 +289,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG") @@ -8452,7 +8445,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) { diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 4e1d5134..f4f8bccb 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -298,24 +298,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) @@ -7915,7 +7908,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) { diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 113a8f9a..35d52fa2 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -298,24 +298,17 @@ function Checks } # Checking services - @("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { - if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) - { - $Localization.WindowsBroken - exit - } - else - { - if ((Get-Service -Name $_).Status -eq "running") - { - $Script:DefenderServices = $true - } - else - { - $Script:DefenderServices = $false - } - } + try + { + $Services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop } + catch [Microsoft.PowerShell.Commands.ServiceCommandException] + { + $Localization.WindowsBroken + exit + } + [array]$notRunning = $Services | Where-Object -FilterScript {$_.Status -ne "running"} + $Script:DefenderServices = $notRunning.Count -eq 0 # Specifies whether Antispyware protection is enabled if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) @@ -7923,7 +7916,7 @@ namespace RegistryUtils uint maxValueLen; uint securityDescriptor; StringBuilder sb; - + if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0) {