From: Jim Clark Date: 2008-01-17T17:59:45+09:00 Subject: Re: iterating through the registry yermej wrote: > On Jan 16, 11:22 pm, Thufir wrote: > >> I want to iterate through the registry, getting results similar to >> "reg query"; what can I do with the "do |reg|", it seems that I need >> to pass something through the "chute": >> Alternatively, you could use rubylogparser which is a wrapper around Microsoft's Log Parser 2.2 (free download from MS web site) to accomplish the same thing. For instance, to query the registry, you would do something similar to: require 'rubylogparser.rb' lp = RubyLogParser.new sql = "Select Path, ValueName INTO STDOUT FROM HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft" lp.open_query('REG', sql, 'CSV', {'e' => 100}) while hash = lp.read_hash do p "#{hash['Path'].ljust(80)} #{hash['ValueName'].rjust(40)}\n" end p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n" p "Statistics:\n" p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n" p "Output: " + (lp.elements_output.nil? ? "0" : "#{lp.elements_output}") + "\n" p "Time: " + (lp.execution_time.nil? ? "0" : "#{lp.execution_time}") + " seconds\n" See the example file in rubylogparser docs (http://rubylogparser.rubyforge.org/doc/) for more info. One thing not in the docs is the {'e' => 100} hash passed to lp.open_query allows Log Parser up to 100 errors before quitting (same as -e:100 command line switch if Log Parser invoked directly). This comes in handy if a registry key cannot be read for whatever reason. Any problems/errors are printed by lp.parse_errors. Hope this is useful. Regards, Jim