Class | Win32::Registry
In: | Win32API/lib/win32/registry.rb
Parent: | Object

### Methods

[] []= _dump close create create created? delete delete_key delete_value each each_key each_value expand_environ flush info inspect keys name new open open open? read read_bin read_i read_s read_s_expand time2wtime type2name write write_bin write_i write_s wtime2time

### Included Modules

Constants Enumerable

### Classes and Modules

Module Win32::Registry::API
Module Win32::Registry::Constants
Class Win32::Registry::Error
Class Win32::Registry::PredefinedKey

### Attributes

disposition | [R] |
hkey | [R] |
keyname | [R] |
parent | [R] |

### Public Class methods

create(hkey, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED) {|obj| ...}

[Source]

    # File Win32API/lib/win32/registry.rb, line 541
        def self.create(hkey, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED)
          newkey, disp = API.CreateKey(hkey.hkey, subkey, opt, desired)
          obj = new(newkey, hkey, subkey, disp)
          if block_given?
            begin
              yield obj
            ensure
              obj.close
            end
          else
            obj
          end
        end

expand_environ(str)

utility functions

[Source]

    # File Win32API/lib/win32/registry.rb, line 495
        def self.expand_environ(str)
          str.gsub(/%([^%]+)%/) { ENV[$1] || $& }
        end

new(hkey, parent, keyname, disposition)

initialize

[Source]

    # File Win32API/lib/win32/registry.rb, line 563
        def initialize(hkey, parent, keyname, disposition)
          @hkey = hkey
          @parent = parent
          @keyname = keyname
          @disposition = disposition
          @hkeyfinal = [ hkey ]
          ObjectSpace.define_finalizer self, @@final.call(@hkeyfinal)
        end

open(hkey, subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED) {|obj| ...}

constructors

[Source]

    # File Win32API/lib/win32/registry.rb, line 526
        def self.open(hkey, subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED)
          subkey = subkey.chomp('\\')
          newkey = API.OpenKey(hkey.hkey, subkey, opt, desired)
          obj = new(newkey, hkey, subkey, REG_OPENED_EXISTING_KEY)
          if block_given?
            begin
              yield obj
            ensure
              obj.close
            end
          else
            obj
          end
        end

time2wtime(time)

[Source]

    # File Win32API/lib/win32/registry.rb, line 517
        def self.time2wtime(time)
          time.to_i * 10000000 + 116444736000000000
        end

type2name(type)

[Source]

    # File Win32API/lib/win32/registry.rb, line 509
        def self.type2name(type)
          @@type2name[type] || type.to_s
        end

wtime2time(wtime)

[Source]

    # File Win32API/lib/win32/registry.rb, line 513
        def self.wtime2time(wtime)
          Time.at((wtime - 116444736000000000) / 10000000)
        end

### Public Instance methods

[](name, *rtype)

[Source]

    # File Win32API/lib/win32/registry.rb, line 690
        def [](name, *rtype)
          type, data = read(name, *rtype)
          case type
          when REG_SZ, REG_DWORD, REG_QWORD, REG_MULTI_SZ
            data
          when REG_EXPAND_SZ
            Registry.expand_environ(data)
          else
            raise TypeError, "Type #{type} is not supported."
          end
        end

[]=(name, rtype, value = nil)

[Source]

    # File Win32API/lib/win32/registry.rb, line 746
        def []=(name, rtype, value = nil)
          if value
            write name, rtype, value
          else
            case value = rtype
            when Integer
              write name, REG_DWORD, value
            when String
              write name, REG_SZ, value
            when Array
              write name, REG_MULTI_SZ, value
            else
              raise TypeError, "Unexpected type #{value.class}"
            end
          end
          value
        end

_dump(depth)

marshalling

[Source]

    # File Win32API/lib/win32/registry.rb, line 600
        def _dump(depth)
          raise TypeError, "can't dump Win32::Registry"
        end

close()

[Source]

    # File Win32API/lib/win32/registry.rb, line 615
        def close
          API.CloseKey(@hkey)
          @hkey = @parent = @keyname = nil
          @hkeyfinal[0] = nil
        end

create(subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED, &blk)

[Source]

    # File Win32API/lib/win32/registry.rb, line 611
        def create(subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED, &blk)
          self.class.create(self, subkey, desired, opt, &blk)
        end

created?()

attributes

[Source]

    # File Win32API/lib/win32/registry.rb, line 576
        def created?
          @disposition == REG_CREATED_NEW_KEY
        end

delete(name)

Alias for delete_value

delete_key(name, recursive = false)

[Source]

    # File Win32API/lib/win32/registry.rb, line 784
        def delete_key(name, recursive = false)
          if recursive
            open(name, KEY_ALL_ACCESS) do |reg|
              reg.keys.each do |key|
                begin
                  reg.delete_key(key, true)
                rescue Error
                  #
                end
              end
            end
            API.DeleteKey(@hkey, name)
          else
            begin
              API.EnumKey @hkey, 0
            rescue Error
              return API.DeleteKey(@hkey, name)
            end
            raise Error.new(5) ## ERROR_ACCESS_DENIED
          end
        end

delete_value(name)

delete

[Source]

    # File Win32API/lib/win32/registry.rb, line 779
        def delete_value(name)
          API.DeleteValue(@hkey, name)
        end

each()

Alias for each_value

each_key() {|subkey, wtime| ...}

[Source]

    # File Win32API/lib/win32/registry.rb, line 644
        def each_key
          index = 0
          while true
            begin
              subkey, wtime = API.EnumKey(@hkey, index)
            rescue Error
              break
            end
            yield subkey, wtime
            index += 1
          end
          index
        end

each_value() {|subkey, type, data| ...}

iterator

[Source]

    # File Win32API/lib/win32/registry.rb, line 624
        def each_value
          index = 0
          while true
            begin
              subkey = API.EnumValue(@hkey, index)
            rescue Error
              break
            end
            begin
              type, data = read(subkey)
            rescue Error
              next
            end
            yield subkey, type, data
            index += 1
          end
          index
        end

flush()

flush

[Source]

    # File Win32API/lib/win32/registry.rb, line 809
        def flush
          API.FlushKey @hkey
        end

info()

key information

[Source]

    # File Win32API/lib/win32/registry.rb, line 816
        def info
          API.QueryInfoKey(@hkey)
        end

inspect()

[Source]

    # File Win32API/lib/win32/registry.rb, line 593
        def inspect
          "\#<Win32::Registry key=#{name.inspect}>"
        end

keys()

[Source]

    # File Win32API/lib/win32/registry.rb, line 658
        def keys
          keys_ary = []
          each_key { |key,| keys_ary << key }
          keys_ary
        end

name()

[Source]

    # File Win32API/lib/win32/registry.rb, line 584
        def name
          parent = self
          name = @keyname
          while parent = parent.parent
            name = parent.keyname + '\\' + name
          end
          name
        end

open(subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED, &blk)

open/close

[Source]

    # File Win32API/lib/win32/registry.rb, line 607
        def open(subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED, &blk)
          self.class.open(self, subkey, desired, opt, &blk)
        end

open?()

[Source]

    # File Win32API/lib/win32/registry.rb, line 580
        def open?
          !@hkey.nil?
        end

read(name, *rtype)

reader

[Source]

    # File Win32API/lib/win32/registry.rb, line 667
        def read(name, *rtype)
          type, data = API.QueryValue(@hkey, name)
          unless rtype.empty? or rtype.include?(type)
            raise TypeError, "Type mismatch (expect #{rtype.inspect} but #{type} present)"
          end
          case type
          when REG_SZ, REG_EXPAND_SZ
            [ type, data.chop ]
          when REG_MULTI_SZ
            [ type, data.split(/\0/) ]
          when REG_BINARY
            [ type, data ]
          when REG_DWORD
            [ type, API.unpackdw(data) ]
          when REG_DWORD_BIG_ENDIAN
            [ type, data.unpack('N')[0] ]
          when REG_QWORD
            [ type, API.unpackqw(data) ]
          else
            raise TypeError, "Type #{type} is not supported."
          end
        end

read_bin(name)

[Source]

    # File Win32API/lib/win32/registry.rb, line 719
        def read_bin(name)
          read(name, REG_BINARY)[1]
        end

read_i(name)

[Source]

    # File Win32API/lib/win32/registry.rb, line 715
        def read_i(name)
          read(name, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD)[1]
        end

read_s(name)

[Source]

    # File Win32API/lib/win32/registry.rb, line 702
        def read_s(name)
          read(name, REG_SZ)[1]
        end

read_s_expand(name)

[Source]

    # File Win32API/lib/win32/registry.rb, line 706
        def read_s_expand(name)
          type, data = read(name, REG_SZ, REG_EXPAND_SZ)
          if type == REG_EXPAND_SZ
            Registry.expand_environ(data)
          else
            data
          end
        end

write(name, type, data)

writer

[Source]

    # File Win32API/lib/win32/registry.rb, line 726
        def write(name, type, data)
          case type
          when REG_SZ, REG_EXPAND_SZ
            data = data.to_s + "\0"
          when REG_MULTI_SZ
            data = data.to_a.join("\0") + "\0\0"
          when REG_BINARY
            data = data.to_s
          when REG_DWORD
            data = API.packdw(data.to_i)
          when REG_DWORD_BIG_ENDIAN
            data = [data.to_i].pack('N')
          when REG_QWORD
            data = API.packqw(data.to_i)
          else
            raise TypeError, "Unsupported type #{type}"
          end
          API.SetValue(@hkey, name, type, data, data.length)
        end

write_bin(name, value)

[Source]

    # File Win32API/lib/win32/registry.rb, line 772
        def write_bin(name, value)
          write name, REG_BINARY, value.to_s
        end

write_i(name, value)

[Source]

    # File Win32API/lib/win32/registry.rb, line 768
        def write_i(name, value)
          write name, REG_DWORD, value.to_i
        end

write_s(name, value)

[Source]

    # File Win32API/lib/win32/registry.rb, line 764
        def write_s(name, value)
          write name, REG_SZ, value.to_s
        end

[Validate]