[Win32utils-devel] win32ole properties question
phasis at gmail.com
Sat Jan 18 04:16:12 UTC 2014
2014/1/18 Daniel Berger <djberg96 at gmail.com>:
> On Fri, Jan 17, 2014 at 8:11 PM, Daniel Berger <djberg96 at gmail.com> wrote:
>> On Fri, Jan 17, 2014 at 7:38 PM, Heesob Park <phasis at gmail.com> wrote:
>>> 2014/1/18 Daniel Berger <djberg96 at gmail.com>:
>>> > Hi all,
>>> > I'm trying to duplicate some code here in the ole branch of
>>> > win32-changejournal:
>>> > http://www.codeproject.com/Articles/42212/WMI-and-File-System-Monitoring
>>> > I'm basically having trouble duplicating this bit:
>>> > objPrevInst.Properties_(objProperty.Name)
>>> > How do I do that with Ruby?
>>> That would be translated as
>> Silly me. I thought I tried that and it didn't work.
> Hm, no, still can't make it work. It's probably something horribly obvious
> but I'm not seeing it.
Here is a whole working translation code:
intInterval = "2"
strDrive = "C:"
strFolder = "\\\\scripts\\\\"
strComputer = "."
# Connect to WMI
objWMIService = WIN32OLE.connect("winmgmts:" +
strComputer + "\\root\\cimv2")
# The query string
strQuery = "Select * From __InstanceOperationEvent" +
" Within " + intInterval +
" Where Targetinstance Isa 'CIM_DataFile'" +
" And TargetInstance.Drive='" + strDrive + "'" +
" And TargetInstance.Path='" + strFolder + "'"
# Execute the query
colEvents = objWMIService.ExecNotificationQuery(strQuery)
# The loop
while true do
# Wait for the next event
# Get SWbemEventSource object
# Get SWbemObject for the target instance
objEvent = colEvents.NextEvent()
objTargetInst = objEvent.TargetInstance
# Check the class name for SWbemEventSource
# It cane be one of the following:
# - __InstanceCreationEvent
# - __INstanceDeletionEvent
# - __InstanceModificationEvent
# If it is file creation or deletion event
# just echo the file name
puts "Created: " + objTargetInst.Name
puts "Deleted: " + objTargetInst.Name
# If it is file modification event,
# compare property values of the target and previous
# instance and echo the properties that have changed
objPrevInst = objEvent.PreviousInstance
objTargetInst.Properties_.each do |objProperty|
if objProperty.Value != objPrevInst.send(objProperty.Name)
puts "Changed: " +
puts "Property: " +
puts "Previous value: " +
puts "New value: " +
More information about the win32utils-devel