Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Win32::Registry#read
read(name, *rtype)
ext/win32/lib/win32/registry.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/win32/lib/win32/registry.rb, line 643
def read(name, *rtype)
type, data = API.QueryValue(@hkey, name)
unless rtype.empty? or rtype.include?(type)
raise TypeError, "Type mismatch (expect [#{
rtype.map{|t|Registry.type2name(t)}.join(', ')}] but #{
Registry.type2name(type)} present)"
end
case type
when REG_SZ, REG_EXPAND_SZ
[ type, data.encode(name.encoding, WCHAR).chop ]
when REG_MULTI_SZ
[ type, data.encode(name.encoding, WCHAR).split(/\0/) ]
when REG_BINARY, REG_NONE
[ 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 #{Registry.type2name(type)} is not supported."
end
end
Read a registry value named name and return array of [ type, data ]. When name is nil, the ‘default’ value is read. type is value type. (see Win32::Registry::Constants module) data is value data, its class is: :REG_SZ, REG_EXPAND_SZ
Example
String
:REG_MULTI_SZ
Example
Array of String
:REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD
Example
Integer
:REG_BINARY, REG_NONE
Example
String (contains binary data)
When rtype is specified, the value type must be included by rtype array, or TypeError is raised.