Avatar of Rupert Eghardt
Rupert Eghardt
Flag for South Africa

asked on 

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)
VB ScriptMicrosoft DevelopmentWindows OS

Avatar of undefined
Last Comment
Rupert Eghardt

8/22/2022 - Mon