Call us Today +1 630 534 0220

We had requirement from client to monitor “ASP” files on server when any files created/modified/deleted email has been sent to the users using Classic ASP vbscript file

Inorder to fulfill the requirement we use following steps.

1. Create Test.vbs files

2. Use winmgmts to monitor the files on the server.First we have to get the object on winmgmts as below.
sPath = “\\ServerName\C$\scripts\test”
sComputer = split(sPath,”\”)(2)
sDrive = split(sPath,”\”)(3)
sDrive = REPLACE(sDrive, “$”, “:”)
sFolders = split(sPath,”$”)(1)
sFolders = REPLACE(sFolders, “\”, “\\”) & “\\”
Set objWMIService = GetObject(“winmgmts:\\” & sComputer & “\root\cimv2″)
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
(“SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE ” _
& “TargetInstance ISA ‘CIM_DataFile’ AND ” _
& “TargetInstance.Drive=’” & sDrive & “‘ AND ” _
& “TargetInstance.Path=’” & sFolders & “‘ AND ” _
& “TargetInstance.Extension = ‘asp’ “)

3. The object colMonitoredEvents will generate the event on any update on monitored folder.
Use below code to get the event fired from colMonitoredEvents.
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Select Case objLatestEvent.Path_.Class
Case “__InstanceCreationEvent”
SendMail “Created”
Case “__InstanceDeletionEvent”
SendMail “Deleted”
Case “__InstanceModificationEvent”
If objLatestEvent.TargetInstance.LastModified <> _
objLatestEvent.PreviousInstance.LastModified then
SendMail “Modified”
End If
End Select

4. we have SendMail function which send email to users once any activity on that folder related to files.
we user persists email sendor program to send an email.
Sub SendMail(mode)
Set Mailer = WScript.CreateObject(“Persits.MailSender”)
Mailer.Host = “x.x.x.x”
Mailer.From = “name@example.com”
Mailer.FromName = “your name”
Mailer.AddAddress “name@example.com”, “name”
Mailer.Subject = “File ” & mode & ” on ” & Now & ” on ” & sComputer & “. “
Mailer.isHTML = true
Mailer.Body = MessageBody
Mailer.Send
Set Mailer = Nothing
End Sub

Happy programming !!!


Do You Need more information ?


For any further information / query regarding Technology, please email us at info@varianceinfotech.com
OR call us on +1 630 861 8263, Alternately you can request for information by filling up Contact Us
facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Leave a Reply

Your email address will not be published. Required fields are marked *

*