將 Regkey 例外狀況新增至 Windows Defender 的腳本

將 Regkey 例外狀況新增至 Windows Defender 的腳本

如果我想要某種腳本為 Windows 檔案防護程式新增排除項,我可以透過將以下文字儲存為 .bat 檔案並執行它來執行以下操作:

powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath "mypath"

但是,如果我想以類似的方式向 Windows Defender 添加一個註冊表項例外,我該如何實現?是否有可能新增一個登錄項目作為 Windows Defender 的例外?

答案1

不是真正的答案,但我透過註冊表來做到這一點,這裡是資訊:

文件和資料夾排除項儲存在下面的登錄項目中。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths

文件類型排除儲存在下面的註冊表項中。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Extensions

進程排除項儲存在下面的登錄項目中。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Processes

真摯地,

阿爾瓦羅·拉馬德里德

答案2

如我所見,您可以使用 Powershell 使用該程式碼建立異常:

Add-MpPreference -ExclusionPath %NameOfThePathOrFile% -Force

-Force命令用於繞過用戶確認。

工作所需的其他功能是以管理員身分執行 PowerShell(至少),因此您可以透過以下方式執行此操作:

reg query "HKU\S-1-5-19\Environment" >nul 2>&1
if not %errorlevel% EQU 0 (
    cls
    powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs"
    exit
)

您可以先進行如下操作:

goto Admin
START Powershell -nologo -noninteractive -windowStyle hidden -noprofile -command ^
Add-MpPreference -ExclusionPath %NameOfThePath% -Force;
:Admin
reg query "HKU\S-1-5-19\Environment" >nul 2>&1
if not %errorlevel% EQU 0 (
    cls
    powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs"
    exit
)

希望有幫助。

相關內容