本帖最后由 batman 于 2013-1-24 21:37 编辑
利用WMI事件监控来完成:- Dim objFSO
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Dim objWMI, objEvents, objEvent
- Set objWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- Dim File, CFile, LogFile
- '如没有与VBS在同一目录下请填写完整路径,并将路径中的\写成\\,如c:\\test\\csjl.txt
- File = "CSJL.txt"
- CFile = Replace(File, "\\", "\")
- '如没有与VBS在同一目录下请填写完整路径
- LogFile = "LXCS.txt"
- objFSO.OpenTextFile(LogFile, 2, True).WriteLine "连赛记录:"
- '设置WMI文件修改事件监控,这里是每60秒监控一次
- Set objEvents = objWMI.ExecNotifiCationQuery _
- ("Select * From __InstanceOperationEvent Within 60 " _
- & "Where TargetInstance Isa 'CIM_DataFile' And " _
- & "TargetInstance.Name='" & File & "'")
- Do While True
- Set objEvent = objEvents.NextEvent()
- If objEvent.Path_.Class = "__InstanceModificationEvent" Then
- Juge
- If Juge <> "" Then _
- objFSO.OpenTextFile(LogFile, 8, True).WriteLine Juge & " Date_Time:" & Now()
- End If
- Loop
-
- Function Juge()
- '重复参赛判断函数
- Dim objStr, Arr, Arr1, Str
- objStr = objFSO.OpenTextFile(CFile).ReadAll()
- Arr = Split(objStr, vbCrLf)
- For i = UBound(Arr) - 1 To UBound(Arr)
- Arr1 = Split(Arr(i), " ")
- For j = 0 To 2
- If InStr(Str, Arr1(j)) = 0 Then
- Str = Str & Arr1(j) & " "
- Else
- Juge = Juge & Arr1(j) & " "
- End If
- Next
- Next
- End Function
复制代码
|