Win32::Registry
win32-registry is registry accessor library for the Windows platform.
It uses Fiddle to call Windows Registry APIs.
Installation
win32-registry is a bundled gem of the ruby standard library, so that the latest version on the ruby release date is preinstalled on Windows.
Other versions of the gem can be installed in addition like so:
Install the gem and add to the application's Gemfile by executing:
$ bundle add win32-registry
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install win32-registry
Usage
require "win32/registry"
Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\foo') do |reg|
value = reg['foo']
value = reg['foo', Win32::Registry::REG_SZ]
type, value = reg.read('foo')
reg['foo'] = 'bar'
reg['foo', Win32::Registry::REG_SZ] = 'bar'
reg.write('foo', Win32::Registry::REG_SZ, 'bar')
reg.each_value { |name, type, data| ... }
reg.each_key { |key, wtime| ... }
reg.delete_value(name)
reg.delete_key(name)
reg.delete_key(name, true)
end
Be sure to use backslashs "\" as path separator.
Forward slashs "/" will not work.
This is in contrast to file paths, which accept forward and backward slashs at will on Windows.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/win32-registry.