首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向Windows Defender添加排除内容,但首先确定它们是否是计算机上的另一个防病毒?

如何向Windows Defender添加排除内容,但首先确定它们是否是计算机上的另一个防病毒?
EN

Stack Overflow用户
提问于 2017-10-11 16:07:37
回答 2查看 2.8K关注 0票数 0

我有一个PowerShell脚本,它将向Windows添加排除。我使用

代码语言:javascript
复制
Add-MpPreference -ExclusionPath "C:\Temp"
Add-MpPreference -ExclusionPath "C:\Users\ME\Desktop"

添加排除,但是如果在计算机上有另一个除Windows之外的反病毒,那么PowerShell会给我一个错误。我需要能够捕获错误,然后有一个弹出窗口,说明已经安装了另一个防病毒。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-17 21:24:54

我自己拿的。我写道:

代码语言:javascript
复制
$AV = Get-CimInstance -Namespace "root\SecurityCenter2" -Class AntiVirusProduct
$installedAV = $AV | Where-Object {$_.displayName -notlike "Windows Defender"}
$otherAV = $AV | Where-Object {$_.displayName -ne "Windows Defender"}

if ($otherAV) {

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Another AV is installed: $($installedAV.displayName)",0,"Error!",16)

}else{

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Only Windows Defender is installed as your AV.",0,"Passed",0)

}
票数 0
EN

Stack Overflow用户

发布于 2017-10-12 08:56:52

如果安装了另一个防病毒程序并处于活动状态,则可以预先检查,而不是捕获错误。

代码语言:javascript
复制
Get-CimInstance -Namespace “root\SecurityCenter2” -Class AntiVirusProduct

您可以将返回的产品状态转换为十六进制,并将其拆分为三个字节块,以检查类型 (第一个字节块)、状态(第二个字节块)以及是否是最新的(第三个字节块)。

代码语言:javascript
复制
('{0:X6}' -f $productState).Substring(2, 2) # 10 should be product is active
('{0:X6}' -f $productState).Substring(4, 2) # 00 should be up to date

请参阅下面的代码作为示例:

代码语言:javascript
复制
$AV = Get-CimInstance -Namespace “root\SecurityCenter2” -Class AntiVirusProduct
$WD = $AV | Where-Object {$_.displayName -like "Windows Defender"}
$installedAV = $AV | Where-Object {$_.displayName -notlike "Windows Defender"}
$productState = [int]('{0:X6}' -f $WD.productState).Substring(2, 2)
if ($productState -eq 10) {
    Add-MpPreference -ExclusionPath "C:\Temp"
    Add-MpPreference -ExclusionPath "C:\Users\ME\Desktop"
} else {
    # https://msdn.microsoft.com/en-us/library/x83z1d9f%28v=vs.84%29.aspx?f=255&MSPPError=-2147217396
    $wshell = New-Object -ComObject Wscript.Shell
    $wshell.Popup("Another AV is installed: $($installedAV.displayName)", 0, "", 0x10)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46692888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档