【发布时间】:2022-01-18 19:40:07
【问题描述】:
您好,我的脚本有问题,我想从该脚本中获得以下内容。首先,我想创建一个文件夹,其中包含特定于我的计算机的月份,并在该文件夹中记录事件日志,但即使脚本以管理员权限运行也没有任何安全性,但仅保存应用程序事件和系统事件。下面是我的脚本
@echo off
rem Script starts here
rem Timestamp Generator
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
:: Format the WMIC command output in YY_MM_DD_hr_mn format
set "YY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "hr=%dt:~8,2%"
set "mn=%dt:~10,2%"
:: Format the MM (month-number) to display the month-name
if %MM%==01 set MM=Ianuarie
if %MM%==02 set MM=Februarie
if %MM%==03 set MM=Martie
if %MM%==04 set MM=Aprilie
if %MM%==05 set MM=Mai
if %MM%==06 set MM=Iunie
if %MM%==07 set MM=Iulie
if %MM%==08 set MM=August
if %MM%==09 set MM=Septembrie
if %MM%==10 set MM=Octombrie
if %MM%==11 set MM=Noiembrie
if %MM%==12 set MM=Decembrie
set "today_date_time=%MM%_%YY%"
echo %today_date_time%
mkdir .\%today_date_time%
rem Set the timestamp format
wevtutil epl System %MM%_%YY%\system.evtx
wevtutil epl Application %MM%_%YY%\application.evtx
wevtutil epl Security %MM%_%YY%\security.evtx
wmic nteventlog where filename='system' cleareventlog
wmic nteventlog where filename='application' cleareventlog
wmic nteventlog where filename='security' cleareventlog
rem End of Script
【问题讨论】:
-
您的代码对我来说可以正常工作。尝试打开命令提示符并从那里运行脚本,而不是双击它来查看是否收到错误消息。
-
我不明白你为什么这样做,为什么不选择其中一个呢?例如,使用
WMIC.exe,您可以将nteventlog与BackUpEventLog方法一起使用,就像您打算使用ClearEventLog方法一样。或者使用wevtutil.exe,您可以一次性完成,%SystemRoot%\System32\wevtutil.exe cl Application /bu:"%today_date_time%\application.evtx",它将在清除事件之前备份事件。至于Security,你确定你有吗?%SystemRoot%\System32\wbem\WMIC.exe nteventlog Get FileName应该告诉你那些存在的。 -
如您所说,我从 cmd 使用管理员权限运行了该程序,但它没有为我生成名为 Security 的事件。忘记一张图片ibb.co/JH5rQYK,我想问你的是如何在月份文件夹中创建一个子文件夹,并且这个新生成的文件夹应该有计算机的名称。
-
Compo 你可以在代码中给我看,我不明白你的意思我是批处理脚本的新手。
-
当然是@Hadad,请给我几分钟的时间在答案区域输入内容。
标签: windows batch-file automation script