johnmcloud Posted October 8, 2012 Share Posted October 8, 2012 (edited) Hi guys, i have found on the forum this script: $strComputer = "." $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2") $colMonitoredEvents = $objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " _ & "Targetinstance ISA 'CIM_DataFile' and " _ & "TargetInstance.Path = '1' and " _ & " TargetInstance.Drive = 'C:' ") While 1 $objEventObject = $colMonitoredEvents.NextEvent() Select Case $objEventObject.Path_.Class()="__InstanceCreationEvent" ConsoleWrite ("A new file was just created: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceDeletionEvent" ;~ ConsoleWrite ("A file was just deleted: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceModificationEvent" ;~ ConsoleWrite ("A file was just modified: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) EndSelect WEnd I need to monitoring a folder for new created files, i don't know if this way is the best. Anyway i have three question: 1) Can't exit, i need to add an HotKeySet and exit + close wmiprvse process? 2) How to add a custom folder? Now the folder is C:1, but I'd like to make a string like: $Folder = "D:TestMyFolder" 3) There is another way for check it out new file created in a folder with Autoit? Thanks for suggestion Edited October 8, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
water Posted October 8, 2012 Share Posted October 8, 2012 There are some filesystem monitoring scripts available on the forum like written by ptrex.Search the forum for "filesystem monitor" and you will find a lot of hits. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
johnmcloud Posted October 8, 2012 Author Share Posted October 8, 2012 (edited) Hi water,Thanks for the answer, but you have posted the same script i have posted on first post I don't need something complex, just an ConsoleWrite when you add a new file in a specific folder. I have searched before doing this, but i have found only 10 result, and that was the only work for me but i have some problem on customization/close correctly.Another cool example is but work as opposite i need...if you delete a file from that folder you have the ConsoleWrite.So, if someone has some idea how to doing my objective or improve the first post please feel free to post here an example script Edited October 8, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
water Posted October 8, 2012 Share Posted October 8, 2012 Sorry, didn't check the content. But as I have done now the two scripts are not 100% identical. If I take your script checking for a variable should look like this:$sDrive = "D:" $sPath = "TestMyFolder" $strComputer = "." $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2") $colMonitoredEvents = $objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " _ & "Targetinstance ISA 'CIM_DataFile' and " _ & "TargetInstance.Path = '" & $sPatch & "' and " _ & " TargetInstance.Drive = '" & $sDrive & "' ") While 1 $objEventObject = $colMonitoredEvents.NextEvent() Select Case $objEventObject.Path_.Class()="__InstanceCreationEvent" ConsoleWrite ("A new file was just created: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceDeletionEvent" ;~ ConsoleWrite ("A file was just deleted: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceModificationEvent" ;~ ConsoleWrite ("A file was just modified: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) EndSelect WEnd My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
johnmcloud Posted October 9, 2012 Author Share Posted October 9, 2012 (edited) Thanks for help, you have make a little mistake in your script ( $sPatch ), i have little edited for add easily the path:HotKeySet("{ESC}", "_Exit") $rPath = @WorkingDir $sDrive = StringLeft($rPath, 2) $sPath = StringTrimLeft(StringReplace($rPath, "", ""),2) & "" $strComputer = "." $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2") $colMonitoredEvents = $objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " _ & "Targetinstance ISA 'CIM_DataFile' and " _ & "TargetInstance.Path = '" & $sPath & "' and " _ & " TargetInstance.Drive = '" & $sDrive & "' ") Static $iCount = 0 While 1 $objEventObject = $colMonitoredEvents.NextEvent() Select Case $objEventObject.Path_.Class() = "__InstanceCreationEvent" $iCount += 1 ConsoleWrite($iCount & " - " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceDeletionEvent" ;~ ConsoleWrite ("A file was just deleted: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) ;~ Case $objEventObject.Path_.Class()="__InstanceModificationEvent" ;~ ConsoleWrite ("A file was just modified: " & $objEventObject.TargetInstance.Properties_.Item("Name").Value & @CR) EndSelect WEnd Func _Exit() Exit 0 EndFuncDon't exit properly when i add a new file:>Process failed to respond; forcing abrupt termination... >Exit code: 1 Time: 12.831How to close this script? Edited October 9, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 You press "Exit" and then you get the "Process failed to respond; forcing abrupt termination..." message? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
johnmcloud Posted October 9, 2012 Author Share Posted October 9, 2012 (edited) Yes, i think that script has some problem...searching i have found another, much better:#include <FileSystemMonitor.au3> HotKeySet("{Esc}", "_Exit") _FileSysMonSetup(3, @WorkingDir, "") Static $iCount = 0 While 1 _FileSysMonDirEventHandler() WEnd Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 Switch $event_id Case 0x00000001 ; file / folder added $iCount += 1 ConsoleWrite($iCount & " - " & $event_value & @CRLF) EndSwitch EndSwitch EndFunc ;==>_FileSysMonActionEvent Func _Exit() Exit 0 EndFunc ;==>_ExitFrom i have not found it in the search...Anyway, i have a last question.I have add a progressive number to every file like:1 - C:Test.exe 2 - C:Test.txt 3 - C:bala.rtf etc.Now i want to add an action to every number of the file, so i want to read from a txt the corresponding line, so if file is 1 read line 1, file 2 read line 2 etc...How to make this?Thanks Edited October 9, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 Use FileOpen / FileReadLine / FileClose. FileReadLine lets you specify the linenumber. Use FileOpen to get a handle for performance reasons. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
johnmcloud Posted October 9, 2012 Author Share Posted October 9, 2012 (edited) I have do this: Local $FileList = FileOpen("List.txt", 2) Func _FileSysMonActionEvent($event_type, $event_id, $event_value) Switch $event_type Case 0 Switch $event_id Case 0x00000001 ; file / folder added $iCount += 1 ;~ ConsoleWrite($iCount & " - " & $event_value & @CRLF) FileWrite($FileList, $iCount & " - " & $event_value & @CRLF) MsgBox(0,0, FileReadLine($FileList, $iCount)) ;~ FileClose($FileList) ; If i put here fileclose i see only one value EndSwitch EndSwitch EndFunc ;==>_FileSysMonActionEvent But i can't see nothing in the MsgBox, what is my error? Edited October 9, 2012 by johnmcloud Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 First close the file, then read it. The line you have written might still be in the buffer. But I wouldn't use this in production because it slows down your script. Open the file at script startup, close it at the end. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
johnmcloud Posted October 11, 2012 Author Share Posted October 11, 2012 Thanks, i'm working on it Link to comment Share on other sites More sharing options...
water Posted October 11, 2012 Share Posted October 11, 2012 Hope you get it working. If you have further questions we will be happy to assist. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now