strComputer = "."
strFile = "C:\program files\dir\name.txt"
dteEndTime = "5:05:00 PM"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '" & Replace(strFile, "\", "\\") & "'")
For Each objFile In colFiles
strOriginalTimestamp = objFile.LastModified
Next
strSubject = "Monitoring script started"
strFrom = "from.com"
strTo = "name.com"
strBody = "The monitoring script has started at " & Now
strServer = "name"
SendEmail strSubject, strFrom, strTo, strBody, strServer
Do While CDate(Time) < CDate(dteEndTime)
' Sleep for one minute
Wscript.Sleep 60000
If CDate(Time) < CDate(dteEndTime) Then
' Check if the current time is on the hour
If Right("0" & Minute(Time), 2) = "00" Then
'Wscript.Sleep 3600000
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '" & Replace(strFile, "\", "\\") & "'")
For Each objFile In colFiles
strLatestTimestamp = objFile.LastModified
Next
ProcessScript
If strLatestTimestamp = strOriginalTimestamp Then
strSubject = "File Date Has Not Changed"
strFrom = "from.com"
strTo = "name.com"
strBody = "The file has not changed since " & strLatestTimeStamp
strServer = "name"
SendEmail strSubject, strFrom, strTo, strBody, strServer
Else
strOriginalTimestamp = strLatestTimeStamp
End If
End If
End If
Loop
' This will trigger when the current time passes the
strSubject = "Monitoring script ended"
strFrom = "from.com"
strTo = "name.com"
strBody = "The monitoring script has ended at " & Now
strServer = "name"
SendEmail strSubject, strFrom, strTo, strBody, strServer
Sub SendEmail(strSubject, strFrom, strTo, strBody, strServer)
Set objEmail = CreateObject("CDO.Message")
On Error Resume Next
objEmail.Subject = strSubject
objEmail.From = strFrom
objEmail.To = strTo
objEmail.TextBody = strBody
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Err.Clear
On Error GoTo 0
End Sub
|