Jump to content
Sign in to follow this  

File monitoring

Recommended Posts



I saw thread about File Monitoring. It is something I need at the moment!

Now Arcker made a sample of how it would work:

$strComputer = "."
 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

 $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()

        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)   

I've made some changes to my liking. However, I got stuck!

This is the part that the script checks for files being made/changed/deleted:

$colMonitoredEvents = $objWMIService.ExecNotificationQuery _
("Select * From __InstanceOperationEvent WITHIN 5 WHERE " _
& "TargetInstance Isa 'Cim_DataFile' And " _
& "TargetInstance.Path = '\\1\\' And " _
& "TargetInstance.Drive = 'C:'")

I need it to check the current userprofile. I just can't get it to work!

I tried "TargetInstance.Path = '\\Documents and Settings\\' and a dozen of other methods, but it's just not working!

Does somebody know?

Thanks in advance! :)

- Zeq

Share this post

Link to post
Share on other sites

Nevermind, got it all working after hours and hours of trying stuff :)

Share this post

Link to post
Share on other sites

oke maybe you can give the answer here for people like me who came here by search and were hoping for the answer?

you have the right script ? of what was the problem?


Share this post

Link to post
Share on other sites


I always use seangriffin's FileSystemMonitor UDF when I need to monitor files and folders. ;)

Very reliable and heartily recommended. :)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this