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

使用VBS通过WMI设置Win32_NTEventlogFile保留周期失败求助

问题:VBS脚本通过WMI修改安全日志保留周期未生效

我尝试用VBS脚本借助WMI将Win32_NTEventlogFile的安全日志设置为保留条目10天,已知修改安全日志需要提升权限的Shell,参考微软示例写了以下代码:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile " _
        & "Where LogFileName='Security'")
For Each objLogFile in colLogFiles
    objLogfile.MaxFileSize = (50*1024)
    objLogFile.OverwriteOutDated=10
    objLogFile.OverwritePolicy=OutDated
    objLogFile.Put_(&H20000)
Next

这段代码能成功修改日志最大文件大小,但无法设置保留周期。修改后查询WMI的OverwriteOutDated值为0,用PowerShell执行Get-Eventlog -List得到结果:

Retain: -1
OverflowAction: DoNotOverwrite

但使用PowerShell命令Limit-EventLog -LogName Security -RetentionDays 10 -OverflowAction OverwriteOlder可以成功设置,结果显示:

Retain: 10
OverflowAction: OverwriteOlder

WMI调用没有返回任何错误,但保留周期设置就是不生效,请问我通过WMI修改保留周期时遗漏了什么?


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 09:16:34