[Win32utils-devel] Filesystem monitoring and ExecNotificationQuery

Daniel Berger djberg96 at gmail.com
Wed Jan 26 06:28:57 EST 2011


On Mon, Jan 24, 2011 at 10:32 PM, Heesob Park <phasis at gmail.com> wrote:
> Hi,
>
> 2011/1/25 Daniel Berger <djberg96 at gmail.com>:
>> Hi,
>>
>> I thought I'd attempt a pure Ruby version of win32-changejournal. I came
>> across this post:
>>
>> http://www.codeproject.com/Articles/42212/WMI-and-File-System-Monitoring.asp
>> x
>>
>> Within it he uses ExecNotificationQuery. However, I can't make it work. I
>> tried this snippet:
>>
> ...
>>
>> Any ideas?
>>
> It seems that folder's separator must be "\\\\".
> Here is a working sample:
>
> # test.rb
> require 'win32ole'
> require 'socket'
>
> host = Socket.gethostname
> con = "winmgmts://#{host}/root/cimv2"
> wmi = WIN32OLE.connect(con)
> drive  = "C:"
> folder = "\\\\Users\\\\phasis"
>
> sql = %Q{
>  select *
>  from __InstanceOperationEvent
>  within 2
>  where TargetInstance isa 'CIM_DataFile'
>  and TargetInstance.Drive='#{drive}'
>  and TargetInstance.Path='#{folder}\\\\'
> }
> events = wmi.ExecNotificationQuery(sql)
> while
>        event = events.NextEvent
>        case event.Path_.Class
>        when "__InstanceCreationEvent"
>                puts "A new file was just created: #{event.TargetInstance.FileName}"
>        when "__InstanceModificationEvent"
>                puts "A file was just modified: #{event.TargetInstance.FileName}"
>        when "__InstanceDeletionEvent"
>                puts "A file was just deleted: #{event.TargetInstance.FileName}"
>        end
> end
> # end test.rb
>
>
> Regards,
> Park Heesob

Excellent, thank you.

Regards,

Dan


More information about the win32utils-devel mailing list