【发布时间】:2012-07-01 04:43:10
【问题描述】:
我的脚本所做的是,首先它检查 C:\Windows\System32\winevt\Logs 中的任何存档事件文件是否超过 7 天。如果是,则删除它们。
它做的第二件事是任何剩余的 Archive*.evtx 文件(那些比 7 天新的文件)它会压缩并发送到您指定的任何路径。
现在我的问题在于我的桌面运行的是 Windows 7 专业版,并且昨晚我正在对其进行最后润色时脚本运行 100% 正确。现在我的笔记本电脑运行的是 Windows Home Premium,所以今天在工作时尝试从我的笔记本电脑运行脚本突然不起作用。
它会将 zip 文件放在正确的路径中,但实际上不会在 zip 文件中放入任何内容。
现在在家里,我必须以管理员身份运行脚本才能使其正常工作,这需要我进行我在网上找到的注册表编辑,甚至在您右键单击 .vbs 文件时添加“以管理员身份运行”按钮. (奇怪的是这已经不存在了,但无论如何)
所以我在笔记本电脑上进行了相同的编辑,尝试再次运行它,但同样的事情发生了。在正确的路径中清空 zip 文件。
所以接下来我发现 UAC 搞砸了它。所以我关闭了笔记本电脑上的 UAC,然后以管理员身份运行,但它仍然遇到了同样的问题。在家里,我的 UAC 仍然处于打开状态,并且脚本可以正常工作,所以我完全不确定问题出在哪里。
然后我想可能是我的笔记本电脑上的 C: 驱动器或类似奇怪的东西存在权限问题。所以我以管理员身份打开 cmd 并运行“takeown”以确保管理员允许访问驱动器。
然后又跑了一遍脚本,还是遇到了同样的问题。
我现在不知道为什么它无法运行,当我下班回家时,我将再次在我的桌面上尝试它,看看它是否仍然有效。 (应该,我没有对脚本做任何改动)
如果有人能在这里帮助我,那就太棒了。我希望在今天之前完成这一切并将其设置为计划任务,以便它开始运行,但它似乎想给我带来更多问题。
脚本如下:
Option Explicit
Dim oFSO, oFolder, sDirectoryPath, sDestinationPath, sOutputFilename, Shell, sFileExt, sFilePrefix
Dim oFileCollection, oFile, sDir
Dim iDaysOld
Set Shell = WScript.CreateObject("WScript.Shell")
'Specify Directory Path From Where You want to clear the old files 'Also where you want destination for zip
sDirectoryPath = "C:\Windows\System32\winevt\Logs\"
sDestinationPath = "C:\Script\files\outzips\"
sOutputFilename = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
sFileExt = ".evtx"
sFilePrefix = "Archive*"
' Specify Number of Days Old File to Delete
iDaysOld = 7
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files
For each oFile in oFileCollection
'Specify the Extension of file that you want to delete 'and the number with Number of character in the file extension
If LCase(oFSO.GetExtensionName(oFile.Name)) = ".evtx" Then
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
End If
Next
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
Dim Command, RetVal
Dim d : d = Date()
Dim dateStr : dateStr = Year(d) & "-" & Right("00" & Month(d), 2) & "-" & Right("00" & Day(d), 2)
Dim t : t = Time()
Dim timeStr: timeStr = Hour(t) & "-" & Right("00" & Minute(t), 2) & "-" & Right("00" & Second(t), 2)
Command = """C:\Program Files\7-zip\7z.exe"" a " & sDestinationPath & sOutputFilename & "-" & dateStr & "-" & timeStr & ".zip " & sDirectoryPath & sFilePrefix & sFileExt
RetVal = Shell.Run(Command,0,true)
【问题讨论】: