VB Script - Check Text file for date

Hi ,
I want to put a script together that checks an output from another system ( output is the date a service ran in a text file )
Need to pull the date , do a compare and send an email if theres a gap of more than 50 mins between now() and the time in the file.

Will scedule the script to run every 5 min...

Any ideas?

Who is Participating?
ADSaundersConnect With a Mentor Commented:
Hi stephengriffin,
This should do the trick. Please note I haven't actually tested this script, but have extracted (and modified) code from working (VB) software on our site. Don't forget to make the changes indicated in the code before running. Just copy & paste into a .vbs file (Suggest DateCheck.vbs), edit it, and run it.

Regards .. Alan

Private Const ForReading = 1
Private Const MapiTo = 1
Private Const Mapicc = 2
Private Const MapiBcc = 3
Private Const fPath = "C:\Time.log" ' Put path to file in here
Dim fso, f, DateAndTime, OSession, Omessage, Recip
Set fso = CreateObject("Scripting.filesystemobject")
Set f = fso.OpenTextFile(FPath, ForReading)
While Trim(f.ReadLine) = "" ' Skip empty lines
DateAndTime = CDate(Trim(f.ReadLine))
Set f = Nothing
If DateDiff("m",DateAndTime, Now) > 50 Then
      Set OSession = CreateObject(MAPI.Session)
      ' Change anything in '<>' to match your environment This is the Exchange account sending the message
      OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
      'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
      Set OMessage = OSession.Outbox.Messages.Add
      ' Repeat this section for all recipients
      Set Recip = OMessage.Recipients.Add
      Recip.Name = "<Who's it going to>"
      Recip.Type = MapiTo ' Subsequent recipients should be Mapicc oe MapiBcc
      ' To here
      Set Recip = Nothing
      OMessage.Subject = "This is your message Subject"
      OMessage.Text = "This is the message Body"
      OMessage.Text = OMessage.text & CHR(10) & "Add this if more than one line"
      Set OMessage = Nothing
      Set OSession = Nothing
End if

In this text file is there only one date at any one time or are there multiple dates that have to be searched through or do you just take the last date that is in there out of all of them or what ?
stephengriffinAuthor Commented:
Hi , the text will be replaced each time within the file.. ie it will just be a date time (now function)

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Sorry left some extraneous code in there:
>    OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
>     'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")

Should be:
    OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
i.e delete the line with my test names in, and uncomment the other.

.. Alan
Sorry again, we're checking for 50 months difference here:
If DateDiff("m",DateAndTime, Now) > 50 Then
Should be:
If DateDiff("n",DateAndTime, Now) > 50 Then

.. Alan
stephengriffinAuthor Commented:
Sorry Alan ! I thought id awared points!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.