You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Set-MpPreference执行失败报错0xc0000142原因排查

问题详情

我编写了一段PowerShell脚本,用于添加Microsoft Defender Antivirus扫描排除文件夹:

Set-MpPreference -ExclusionPath D:\vpostest
echo "Exclusion Success"
Read-Host -Prompt "Press Enter to exit"

执行脚本时出现错误:

Set-MpPreference : Operation failed with the following error: 0x%1!x!
At C:\Users\zainur.ariffin\Desktop\Powershell test\autoExclusion.ps1:1 char:1
+ Set-MpPreference -ExclusionPath D:\vpostest
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_MpPreference:root\Microsoft\...FT_MpPreference) [Set-MpPreference], CimException
    + FullyQualifiedErrorId : HRESULT 0xc0000142,Set-MpPreference

已确认Microsoft Defender Antivirus已启用,重启过电脑,也用Get-MpComputerStatus检查过状态,但错误仍存在,请问原因是什么?

可能的原因及解决办法
  • 权限不足:Set-MpPreference必须以管理员权限运行。右键点击PowerShell,选择「以管理员身份运行」后再执行脚本,这是最常见的触发原因。
  • Defender服务异常:虽然Get-MpComputerStatus显示启用,但核心服务可能未正常工作。按Win+R输入services.msc,找到「Microsoft Defender Antivirus Service」(Win10)或「Defender Antivirus Service」(Win11),检查是否处于运行状态。未运行则右键启动,已运行则重启服务后再尝试。
  • 目标路径不存在:确认D:\vpostest文件夹实际存在。可先执行Test-Path D:\vpostest验证路径有效性,返回False的话先创建文件夹再添加排除。
  • 组策略/Intune限制:企业环境下可能存在组策略或Intune配置,禁止修改Defender排除项。打开本地组策略编辑器(gpedit.msc),查看「计算机配置>管理模板>Windows组件>Microsoft Defender Antivirus>排除项」的设置,检查是否有强制限制规则。
  • Defender进程卡死:打开任务管理器,找到「MsMpEng.exe」进程,结束后等待系统自动重启该进程,再执行脚本。
  • 系统文件损坏:少数情况是系统文件损坏导致Defender功能异常。依次执行sfc /scannow和DISM /Online /Cleanup-Image /RestoreHealth修复系统文件,完成后重启电脑再测试。

内容的提问来源于stack exchange,提问作者Zafzaa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 21:30:06