Registry.rb problem?

I just found out about registry.rb in the Win32 distribution of Ruby (it’s
for accessing the Windows registry).

However, when I tried the sample script:

require ‘win32/registry.rb’

Win32::Registry::HKEY_CURRENT_USER.open(‘SOFTWARE\foo’) do |reg|

value = reg['foo']                               # read a value

value = reg['foo', Win32::Registry::REG_SZ]      # read a value with

type

type, value = reg.read('foo')                    # read a value

#reg['foo'] = 'bar'                               # write a value

#reg['foo', Win32::Registry::REG_SZ] = 'bar'      # write a value

with type

#reg.write('foo', Win32::Registry::REG_SZ, 'bar') # write a value



reg.each_value { |name, type, data|

  puts "name is: #{name}, type is: #{type}, data is: #{data}"

}        # Enumerate values

end

I got:

c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:340:in `initialize’:
uninitializ

ed constant Win32::Registry::Error::Errno (NameError)

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:340:in

`initialize’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:395:in

`exception’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:395:in

`raise’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:395:in

`check’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:417:in

`OpenKey’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:525:in

`open’

    from c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:605:in

`open’

    from registry.rb:2

Any ideas?

Phil

I got:

···

On Sat, 20 Dec 2003, Phil Tomson wrote:

c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:340:in `initialize’:

uninitializ

ed constant Win32::Registry::Error::Errno (NameError)

Phil, what’s your ruby -v? I’m not able to reproduce this. I get:

c:/ruby/lib/ruby/1.8/win32/registry.rb:528:in open': The system cannot find the file specified. (Win32::Registry::Error) from c:/ruby/lib/ruby/1.8/win32/registry.rb:608:inopen’
from registry.rb:2

Chad

Phil Tomson wrote:

I just found out about registry.rb in the Win32 distribution of Ruby (it’s
for accessing the Windows registry).

I got:

c:/programs/ruby/lib/ruby/1.8/win32/registry.rb:340:in `initialize’:
uninitialized constant Win32::Registry::Error::Errno (NameError)

Any ideas?

Phil

There were slight changes in Rev 1.2, yours is Rev 1.1

···

? Quick fix:

Replace line 333:
class Error < ::SystemCallError
with:
class Error < ::StandardError


Or d/l from CVSweb
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/Win32API/lib/win32/registry.rb

Next to “Revision 1.2”, right-click on (download) and “Save target as …”

                                                    (depending on your browser)

I think Usa is the [author/]maintainer (U.Nakamura usa@osb.att.ne.jp)

daz