VB Script - File Monitoring

Hi Guys,

I have a working VB Script - sending an e-mail.  (Please see script below)
I would like to modify the script to include a conditional trigger.

The script will be called every 5 minutes from Windows Task Scheduler, but should only trigger an e-mail, if a "file being monitored" is older than 15 minutes.

For example:  We have a reporting tool, writing a file to:  C:\OUTPUT\Report.PDF

We need an e-mail notification, if the time-stamp of the file (Report.PDF) is older than 15 minutes (Thus not replaced or updated)

My Current Working VB Script:

on error resume next
 
Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf
 
' E-mail properties
Set oMsg      = CreateObject("CDO.Message")
oMsg.From     = "user@domain.com"  ' or "Sender Name <from@gmail.com>"
oMsg.To       = "user@domain.com"    ' or "Recipient Name <to@gmail.com>"
oMsg.Subject  = "Messaging Script"
oMsg.TextBody = "Messaging Script"
 
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver")       = "mail.domain.com" 'server address
oConf.Fields(schema & "smtpserverport")   = 587              'port number
oConf.Fields(schema & "sendusing")        = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic         'authentication type
oConf.Fields(schema & "smtpusessl")       = "False"             'use SSL encryption
oConf.Fields(schema & "sendusername")     = "user@domain.com" 'sender username
oConf.Fields(schema & "sendpassword")     = "Password"      'sender password
oConf.Fields.Update()
 
' send message
oMsg.Send()
 
' Return status message
If Err Then
    resultMessage = "ERROR " & Err.Number & ": " & Err.Description
    Err.Clear()
Else
    resultMessage = "Message sent ok"
End If
 
'Wscript.echo(resultMessage)
Rupert EghardtProgrammerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
On the road so can't test this, but it should hopefully give you enough of the idea to get what you want.  Take a look and see if it makes sense.

on error resume next
 
Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Const CheckFile = "C:\OUTPUT\Report.PDF"
Const AgeInMins = 15

Dim oMsg, oConf
Dim objFSO, strFile, objFile
 
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
strFile = objFSO.GetAbsolutePathname(CheckFile)
If Not objFSO.FileExists(strFile) Then
    ' ***** WHAT DO YOU WANT TO DO IF FILE DOESN'T EXIST? *****
    Wscript.Quit
Else
    Set objFile = objFSO.GetFile(strFile)
    If DateDiff("n", objFile.DateLastModified, Now) <= AgeInMins Then
        Wscript.Quit
    End If
End If 
 
' E-mail properties
Set oMsg      = CreateObject("CDO.Message")
oMsg.From     = "user@domain.com"  ' or "Sender Name <from@gmail.com>"
oMsg.To       = "user@domain.com"    ' or "Recipient Name <to@gmail.com>"
oMsg.Subject  = "Messaging Script"
oMsg.TextBody = "Messaging Script"
 
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver")       = "mail.domain.com" 'server address
oConf.Fields(schema & "smtpserverport")   = 587              'port number
oConf.Fields(schema & "sendusing")        = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic         'authentication type
oConf.Fields(schema & "smtpusessl")       = "False"             'use SSL encryption
oConf.Fields(schema & "sendusername")     = "user@domain.com" 'sender username
oConf.Fields(schema & "sendpassword")     = "Password"      'sender password
oConf.Fields.Update()
 
' send message
oMsg.Send()
 
' Return status message
If Err Then
    resultMessage = "ERROR " & Err.Number & ": " & Err.Description
    Err.Clear()
Else
    resultMessage = "Message sent ok"
End If

Open in new window


»bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rupert EghardtProgrammerAuthor Commented:
Working well! ;-)

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.