Hi Again, Should have checked inside my Outbox before sending. The editor likes to hide things and the WE does not read it until closed and re-opened... The error is the case statement which I thought maybe I did not copy over but it was there just not being read. If anyone would note the case before and after the Select Case start, I had inserted one thinking I had not copied it. Sent: Wednesday, January 28, 2015 1:18 AM Subject: Re: Think I could need a bit of help...
Hi Chip, Below is the guts of it. I hope I did not miss something but this is it. I do not use the datafile target so drive and folder are not used. Bruce 'Global Variables: Dim MonitorActive: MonitorActive = False 'Set With Buttons Activate&Clear Dim strDrive, strPath, strFolder strDrive = "" 'Not Used 'Path set by edit box entry: strPath = "" 'Format: c:\\\\ or c:\\\\program files\\\\ strFolder = "" 'Not used. Dim strComputer, strQuery, strPollingInterval, strTarget, strGroup strComputer = "." 'Local Computer. strPollingInterval = "5" 'Seconds to check events. strTarget = "'CIM_DirectoryContainsFile'" 'Intrinsic or extrinsic event to target. 'Format: "'Win32_Directory.Name=""c:\\\\downloads\\\\""'" strGroup = "Win32_Directory.Name=""" 'Event Class to look for and the path that follows starts with a quote. 'Main Function: Function MainDialog(...) Select Case dId ... Case "btn_monitor_off" If dEvent = buttonClicked Then MonitorActive = False Speak " Monitoring Path Is Off ", SpeakerVoice Sleep 1000 End If MainDialogProc = True Exit Function Case "btn_monitor_event" If dEvent = buttonClicked Then Speak " Now Monitoring Path: " _ & dObj.Control( "eb_path").Text, SpeakerVoice Sleep 1000 Speak "Set To: " & SetDrivePath( dObj.Control( "eb_path").Text), SpeakerVoice Sleep 1000 Queue "SetDriveMonitoring", dObj.Control( "eb_path").text End If MainDialogProc = True Exit Function ... End Select ... End Function Sub SetDriveMonitoring( ByVal strDrivePath) 'Monitor the drive selected. strPath = SetDrivePath( strDrivePath) Dim objWMIService, colMonitoredEvents, objEventObject DoEvents Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") strQuery = "SELECT * FROM __InstanceOperationEvent" _ & " WITHIN " & strPollingInterval _ & " WHERE TargetInstance ISA " & strTarget _ & " and TargetInstance.GroupComponent= " _ & "'" & strGroup & strPath & """'" Set colMonitoredEvents = objWMIService.ExecNotificationQuery( strQuery) DoEvents MonitorActive = True Do While MonitorActive Set objEventObject = colMonitoredEvents.NextEvent() DoEvents Select Case objEventObject.Path_.Class Case "__InstanceCreationEvent" Speak "A new file was just created: " _ & GetPath_FileName( objEventObject.TargetInstance.PartComponent), speakerVoice Case "__InstanceDeletionEvent" Speak "A file was just deleted: " _ & GetPath_FileName( objEventObject.TargetInstance.PartComponent), speakerVoice Case "__InstanceModificationEvent" 'Speak "A file was just Modified: " _ ' & GetPath_FileName( objEventObject.TargetInstance.PartComponent), speakerVoice End Select DoEvents Loop End Sub Function GetPath_FileName( strData) 'Extract The Path and File name. Dim pos, name pos = InStr(1, strData, "name=", VbTextCompare) If pos > 0 then name = Mid( strData, pos + 5) name = Replace( name, CStr( Chr(34)), "") name = Replace( name, "\\", "\") Else name = strData End If GetPath_FileName = name End Function Function SetDrivePath( ByVal strPath) 'Format: strPath = strDrivePath '"h:\\\\vb\\\\file" strPath = strPath & "\" strPath = Replace( strPath, "\\\\", "\") strPath = Replace( strPath, "\\\", "\") strPath = Replace( strPath, "\\", "\") strPath = Replace( strPath, "\", "\\\\") If Mid(strPath, 2, 1) = "\" Then strPath = Left(strPath, 1) & ":" & Mid(strPath, 2) SetDrivePath = strPath End Function Sent: Tuesday, January 27, 2015 8:26 PM Subject: RE: Think I could need a bit of help... I would (as always) appreciate seeing it Bruce. How about just making it the contents of a message here so everyone can look it over? Thanks. Chip acora...@comcast.net -----Original Message----- From: LBX [mailto:lab...@fltg.net] Sent: Sunday, January 25, 2015 11:39 PM To: gw-scripting@gwmicro.com Subject: Re: Think I could need a bit of help... Hi! I wrote an app for drive monitoring and sent a copy to David and Rick. If anyone wants a copy just write to me. The app inserts the required \ chars for the registry wants 2 of them and you have to double each to insure one gets inserted. --- This email has been checked for viruses by Avast antivirus software. http://www.avast.com