• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

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?

  • 3
  • 2
1 Solution
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)

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now