[Win32utils-devel] Filesystem monitoring and ExecNotificationQuery

Daniel Berger djberg96 at gmail.com
Mon Jan 24 21:20:56 EST 2011


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:

# test.rb
require 'win32ole'
require 'socket'

host = Socket.gethostname

con = "winmgmts://#{host}/root/cimv2"
wmi = WIN32OLE.connect(con)

drive  = "C:"
folder = "\\Users\\djberge"

sql = %Q{
  select *
  from __InstanceOperationEvent
  within 2
  where TargetInstance isa 'CIM_DataFile'
  and TargetInstance.Drive='#{drive}'
  and TargetInstance.Path='#{folder}'
}

events = wmi.ExecNotificationQuery(sql)
# end test.rb

Here were the results:

c:\Users\djberge >ruby test.rb
test.rb:20:in `method_missing': ExecNotificationQuery (WIN32OLERuntimeError)
    OLE error code:80041058 in SWbemServicesEx
      Unparsable query.
    HRESULT error code:0x80020009
      Exception occurred.
        from test.rb:20

Tried it with JRuby, too:

c:\Users\djberge >jruby test.rb
Dispatch.java:-2:in `invokev': org.racob.com.ComFailException: Invoke of:
ExecNotificationQuery
Source: SWbemServicesEx
Description: Unparsable query.

        from Dispatch.java:243:in `invokev'
        from Dispatch.java:187:in `callN'
        from RubyWIN32OLE.java:203:in `invokeMethodOrGet'
        from RubyWIN32OLE.java:112:in `method_missing'
        from
org/jruby/ext/win32ole/RubyWIN32OLE$i_method_0_0$RUBYINVOKER$method_missing.
gen:65535:in `call'
        from JavaMethod.java:642:in `call'
        from RuntimeHelpers.java:401:in `call'
        from DynamicMethod.java:190:in `call'
        from CachingCallSite.java:375:in `callMethodMissing'
        from CachingCallSite.java:306:in `cacheAndCall'
        from CachingCallSite.java:148:in `call'
        from test.rb:20:in `__file__'
        from test.rb:-1:in `load'
        from Ruby.java:690:in `runScript'
        from Ruby.java:573:in `runNormally'
        from Ruby.java:416:in `runFromMain'
        from Main.java:286:in `run'
        from Main.java:128:in `run'
        from Main.java:97:in `main'

Any ideas?

Regards,

Dan



More information about the win32utils-devel mailing list