yermej
1/17/2008 7:56:00 AM
On Jan 16, 11:22 pm, Thufir <hawat.thu...@gmail.com> 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":
>
> C:\code\reg>
> C:\code\reg>type reg.rb
> require 'rubygems'
> require 'win32/registry'
> include Win32
>
> #desired output to match the output of:
> #reg query HKEY_LOCAL_MACHINE\Software\Policies\Microsoft
>
> Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,'Software
> \Policies\Micr
> osoft')
>
> #do |reg|
> # type, data = reg.read('DataBasePath')
>
> C:\code\reg>
> C:\code\reg>ruby reg.rb
>
> C:\code\reg>
> C:\code\reg>
>
> thanks,
>
> Thufir
I just threw this together. It seems to work though doesn't do quite
as well with the number of tabs separating value columns.
require 'win32/registry'
include Win32
require 'win32/registry'
include Win32
class Registry
def query
res = [self.name]
self.each_key do |subkey, wtime|
res << "#{self.name}\\#{subkey}"
end
self.each_value do |value, type, data|
data = self.read(value, type)
case type
when REG_BINARY
data[1] = data[1].unpack('H*') if type ==
Registry::REG_BINARY
when REG_DWORD
data[1] = "0x#{data[1].to_s(16)}"
end
res << "#{value}\t#{Registry.type2name(type)}\t#{data[1]}"
end
res
end
end
puts Registry.open(Registry::HKEY_LOCAL_MACHINE, 'Software\Policies
\Microsoft').query.join("\n\n")