vb update

B0b_shiska
B0b_shiska used Ask the Experts™
on
Hello. i have a script that watches a constantly updating xml file for inactivity. At the moment, the script will send an email if the file has not updated in x time. Since the script will be running constantly, are there are performance enhancements or modifications that can be carried out on the script? Thanks in advance.

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_Datafile Where Name = 'C:\\programfiles\\filepath\\name.xml'")

For Each objFile in colFiles
    strOriginalTimestamp = objFile.LastModified
Next

Do While True
    Wscript.Sleep 3600000
    Set colFiles = objWMIService.ExecQuery _
        ("Select * from CIM_Datafile Where Name = 'C:\\programfiles\\filepath\\name.xml'")

    For Each objFile in colFiles
        strLatestTimestamp = objFile.LastModified
    Next

Set objEmail = CreateObject("CDO.Message")

On Error Resume Next    
   ProcessScript
    If strLatestTimestamp <> strOriginalTimestamp Then
        strOriginalTimestamp = strLatestTimeStamp
    Else
        objEmail.Subject = "emailsubject."
    objEmail.From = "123@name.com"
    objEmail.To = "abc@xyz.com"
    objEmail.TextBody = ("text.")
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "servername"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = #
    objEmail.Configuration.Fields.Update
    objEmail.Send
   End If    
Loop
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
i would use the task scheduler to schedule a run of this vbs script every 6 minutes (3600000/1000/60) and remove the "Wscript.Sleep 3600000" line
Commented:
correction:
also remove the "Do While True" and the "Loop" lines

Author

Commented:
Thanks ptessel. Any way to have the script run constantly, and somehow reset itself when it finds the file has not updated. The reset is to minimize memory utilization by the script. Thanks in advance.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial