Browse Source

#430 | DefenderServices check (edge-cases)

pull/431/head
Alan Płócieniak 2 years ago
parent
commit
10eddcd7ad
  1. 28
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  2. 28
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  3. 28
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  4. 28
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  5. 28
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  6. 28
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

28
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -289,24 +289,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken }
exit catch [Microsoft.PowerShell.Commands.ServiceCommandException] {
} $Localization.WindowsBroken
else exit
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
[array]$notRunning = $services | Where-Object -FilterScript {$_.Status -ne "running"}
$Script:DefenderServices = $notRunning.Count -eq 0
# Specifies whether Antispyware protection is enabled # Specifies whether Antispyware protection is enabled
if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG") if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG")
@ -8444,7 +8436,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

28
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -271,24 +271,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken
exit
}
else
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
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 # Specifies whether Antispyware protection is enabled
if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled)
@ -6877,7 +6869,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

28
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -271,24 +271,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken
exit
}
else
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
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 # Specifies whether Antispyware protection is enabled
if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled)
@ -7498,7 +7490,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

28
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -289,24 +289,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken }
exit catch [Microsoft.PowerShell.Commands.ServiceCommandException] {
} $Localization.WindowsBroken
else exit
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
[array]$notRunning = $services | Where-Object -FilterScript {$_.Status -ne "running"}
$Script:DefenderServices = $notRunning.Count -eq 0
# Specifies whether Antispyware protection is enabled # Specifies whether Antispyware protection is enabled
if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG") if ((Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion" -Name EditionID) -ne "EnterpriseG")
@ -8452,7 +8444,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

28
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -298,24 +298,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken
exit
}
else
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
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 # Specifies whether Antispyware protection is enabled
if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled)
@ -7915,7 +7907,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

28
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -298,24 +298,16 @@ function Checks
} }
# Checking services # Checking services
@("Windefend", "SecurityHealthService", "wscsvc") | ForEach-Object -Process { try
if ($null -eq (Get-Service -Name $_ -ErrorAction Ignore)) {
{ $services = Get-Service -Name Windefend, SecurityHealthService, wscsvc -ErrorAction Stop
$Localization.WindowsBroken
exit
}
else
{
if ((Get-Service -Name $_).Status -eq "running")
{
$Script:DefenderServices = $true
}
else
{
$Script:DefenderServices = $false
}
}
} }
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 # Specifies whether Antispyware protection is enabled
if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled) if ((Get-CimInstance -ClassName MSFT_MpComputerStatus -Namespace root/microsoft/windows/defender).AntispywareEnabled)
@ -7923,7 +7915,7 @@ namespace RegistryUtils
uint maxValueLen; uint maxValueLen;
uint securityDescriptor; uint securityDescriptor;
StringBuilder sb; StringBuilder sb;
if (RegQueryInfoKey(hKey, out sb, ref lpcbClass, lpReserved, out lpcbSubKeys, out lpcbMaxKeyLen, out lpcbMaxClassLen, 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) out lpcValues, out maxValueName, out maxValueLen, out securityDescriptor, ref lastModified) != 0)
{ {

Loading…
Cancel
Save