I need a script to notify me if files are added to a folder. I have gotten some code form the Microsoft site and modified it.The original code displayed a message box that you would click off of. It worked fine. I substituted code for the sending of the email. It works as well only the email loops and continuously sends emails. I need the email to send and the stop yet have the script continue to run to monitor the folder. This is what I have so far.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
sonate}!\\
" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotifica
tionQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile
' and " _
& "TargetInstance.GroupCompo
nent= " _
& "'Win32_Directory.Name=""c
:\\\\dropb
ox""'")
Do
Dim objMessage
Set objMessage = CreateObject("CDO.Message"
)
objMessage.Subject = "New Files Have Been Added"
objMessage.From = "newfiles@yourdomainname.c
om"
objMessage.To = "user@yourdomain.com"
objMessage.TextBody = "You have new files in the folder foldername."
objMessage.Configuration.F
ields.Item
_
("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.F
ields.Item
_
("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = "yourmailserver.com"
'Server port (typically 25)
objMessage.Configuration.F
ields.Item
_
("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.F
ields.Upda
te
objMessage.Send
Loop
Start Free Trial