Hello all. I need a script that will repeatedly check a folder every 30
minutes, and tell me if no new files have been created during that time
interval. I've taken the script found here:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1011.mspx

and tried to tweak it to no avail.

Any help would be greatly appreciated. Thanks!

- Dave

Re: How to monitor for the absence of any new files created in a folder? by Nathan

Nathan
Wed Sep 13 07:50:52 CDT 2006


Highlander wrote:
> Hello all. I need a script that will repeatedly check a folder every 30
> minutes, and tell me if no new files have been created during that time
> interval. I've taken the script found here:
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1011.mspx
>
> and tried to tweak it to no avail.
>
> Any help would be greatly appreciated. Thanks!
>
> - Dave

Generally when files are created inside of a folder, that folder's
modified date changes. So what I would do is write a script that checks
the modified date/time of the folder and if that date is more than 30
minutes, fire off an e-mail.


Re: How to monitor for the absence of any new files created in a folder? by TDM

TDM
Wed Sep 13 09:18:15 CDT 2006


"Highlander" <tron9901@msn.com> wrote in message
news:1158105580.936013.295850@p79g2000cwp.googlegroups.com...
> Hello all. I need a script that will repeatedly check a folder every 30
> minutes, and tell me if no new files have been created during that time
> interval. I've taken the script found here:
>
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1011.mspx
>
> and tried to tweak it to no avail.
>
> Any help would be greatly appreciated. Thanks!
>
> - Dave
>

Dave,

Here is a script I put together a while back, mostly from a sample
script from M$. Seems to work, I just tested it but I also seem to
recall that when I did my research on this, there were some issues
with using WMI to monitor for events. Lets say your interval was
set at 30 minutes, and at 10 minutes a file is created in the folder
you are monitoring, but then gets deleted at 20 minutes, then I do
believe this script will miss that. For what it's worth, here it is.

WATCH FOR LINE WRAP !!!


Call monitorFolderForAdd("", "C:\temp", 10)

Function monitorFolderForAdd(strComputer, strFolder, iInterval)
' Script to monitor folder for file additons

Dim objWMIService
Dim colMonitoredEvents
Dim objLatestEvent

If strComputer = "" Then strComputer = "."
If iInterval = "" Then iInterval = 10
If strFolder = "" Then
WScript.Echo "Sorry, you must supply a FOLDER FULLPATH to watch, exiting
now..."
WScript.Quit
Else
strFolder = Replace(strFolder, "\", "\\\\")
End If

WScript.Echo "Monitoring " & strFolder & " for File Additions at a " &
iInterval & " second interval..."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery("SELECT * FROM
__InstanceCreationEvent WITHIN " & iInterval & " WHERE Targetinstance ISA
'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent=
'Win32_Directory.Name=""" & strFolder & """'")

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop

End Function


TDM



Re: How to monitor for the absence of any new files created in a folder? by Highlander

Highlander
Thu Sep 21 13:44:03 CDT 2006


TDM wrote:
> "Highlander" <tron9901@msn.com> wrote in message
> news:1158105580.936013.295850@p79g2000cwp.googlegroups.com...
> > Hello all. I need a script that will repeatedly check a folder every 30
> > minutes, and tell me if no new files have been created during that time
> > interval. I've taken the script found here:
> >
> > http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1011.mspx
> >
> > and tried to tweak it to no avail.
> >
> > Any help would be greatly appreciated. Thanks!
> >
> > - Dave
> >
>
> Dave,
>
> Here is a script I put together a while back, mostly from a sample
> script from M$. Seems to work, I just tested it but I also seem to
> recall that when I did my research on this, there were some issues
> with using WMI to monitor for events. Lets say your interval was
> set at 30 minutes, and at 10 minutes a file is created in the folder
> you are monitoring, but then gets deleted at 20 minutes, then I do
> believe this script will miss that. For what it's worth, here it is.
>
> WATCH FOR LINE WRAP !!!
>
>
> Call monitorFolderForAdd("", "C:\temp", 10)
>
> Function monitorFolderForAdd(strComputer, strFolder, iInterval)
> ' Script to monitor folder for file additons
>
> Dim objWMIService
> Dim colMonitoredEvents
> Dim objLatestEvent
>
> If strComputer = "" Then strComputer = "."
> If iInterval = "" Then iInterval = 10
> If strFolder = "" Then
> WScript.Echo "Sorry, you must supply a FOLDER FULLPATH to watch, exiting
> now..."
> WScript.Quit
> Else
> strFolder = Replace(strFolder, "\", "\\\\")
> End If
>
> WScript.Echo "Monitoring " & strFolder & " for File Additions at a " &
> iInterval & " second interval..."
>
> Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
> & strComputer & "\root\cimv2")
> Set colMonitoredEvents = objWMIService.ExecNotificationQuery("SELECT * FROM
> __InstanceCreationEvent WITHIN " & iInterval & " WHERE Targetinstance ISA
> 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent=
> 'Win32_Directory.Name=""" & strFolder & """'")
>
> Do
> Set objLatestEvent = colMonitoredEvents.NextEvent
> Wscript.Echo objLatestEvent.TargetInstance.PartComponent
> Loop
>
> End Function
>
>
> TDM

TDM,

Thanks for the suggestion. As it turns out, I took another approach and
found an answer to my problem. If anyone's interested you can find it
here:

http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/403838adf576e025/6eeecd2c2c6ff340?hl=en#6eeecd2c2c6ff340