| 1. |
Solve : No activity monitor in a folder? |
|
Answer» Hi Guys set /a r=%time:~3,1%-1 FBThanks for the all the reply . I was trying to do the VB script as sidewinder says and got the folloing error : C:\>cscript no.vbs C:\no.vbs(12, 1) Microsoft VBScript runtime error: Object required: 'stance' Is taht make any sence ? Sorry about that. The line in question was a comment. Code: [Select]strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 3 WHERE " _ & "Targetinstance ISA 'CIM_Datafile' and " _ & "TargetInstance.Drive = 'c:' And "_ & "TargetInstance.Path= '\\scripts\\'") Do Set objLatestEvent = colMonitoredEvents.NextEvent() Select Case objLatestEvent.Path_.Class Case "__InstanceCreationEvent" WScript.Echo "File Created: " & objLatestEvent.TargetInstance.Name Case "__InstanceDeletionEvent" WScript.Echo "File Deleted: " & objLatestEvent.TargetInstance.Name Case "__InstanceModificationEvent" WScript.Echo "File Modified: " & objLatestEvent.TargetInstance.Name End Select Loop This script was designed to issue a message whenever an event occurred in the c:\script directory. You will need to modify the script to monitor no events happening. One way would be to note the times any events OCCUR. When the time difference between two events exceeds 10 minutes, you'll have your period of inactivity. Mostly, monitor scripts (you can monitor most anything) are used to trigger another event or to create documentation of some activity. Hmmm, a new concept, a monitor script to monitor non-events. Thanks Sidewinder I am not that smart to do what you are saying as I am not from a computer background ...Is it possible to implement by you , what you are saying (One way would be to note the times any events occur. When the time difference between two events exceeds 10 minutes, you'll have your period of inactivity.) ..It might be very easy code for you and will take 5 mins but to me ..it seems very complex .. Thanks for helping me so far Hi Sidewinder Also with my other script I have ..I use bmail (which is command line mail ) to send me a email then exceed the thresold .I have used that in batch script before and working good .(Dont know how you can use that in VB Script) Is it also possible to send email using bmail program when there is no activity in the folder for 10 mins ...? This script will be very help full for me ...of what I am doing right the moment ... Sorry to be a pain for asking you so many things . Many Thanks in advance ... A monitor script is designed to wait for an event to occur and then do some work. In no event occurs, no work is performed. You can see the dilemma of monitoring non-events. I was able to get these two scripts to work in a controlled environment. The first script monitors and times stamps directory activity. The second script calculates the time difference between the last event and the CURRENT time. When the difference gets to ten, we have liftoff Script 1 Code: [Select]Const ForWriting = 2 strComputer = "." Set fso = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 3 WHERE " _ & "Targetinstance ISA 'CIM_Datafile' and " _ & "TargetInstance.Drive = 'c:' And "_ & "TargetInstance.Path= '\\scripts\\'") Do Set objLatestEvent = colMonitoredEvents.NextEvent() Set f = fso.OpenTextFile("c:\temp\Timer.txt", ForWriting, True) Select Case objLatestEvent.Path_.Class Case "__InstanceCreationEvent" f.WriteLine Now Case "__InstanceDeletionEvent" f.WriteLine Now Case "__InstanceModificationEvent" f.WriteLine Now End Select f.Close Loop Script 2 Code: [Select]Const ForReading = 1 Set WshShell = CreateObject("Wscript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") Do Set f = fso.OpenTextFile("c:\temp\Timer.txt", ForReading) strTime = f.ReadLine If DateDiff("n", CDate(strTime), Now) > 10 Then WshShell.Run "bmail ........",,True Exit Do End If f.Close WScript.Sleep 30000 Loop I'm not familiar with bmail so you need to fill in the dotted line. Good luck. Do not put the scripts in the directory being monitored.Thanks a Lot sidewinder .. My problem has been FIXED .. Thanks to all for putting suggestion and help me out .. This was my first post on the forum and I have started like this forum already , because of u all helping ppl over there .. Thanks again |
|