Module: MiniRegistry
- Included in:
- OraConf
- Defined in:
- ext/oci8/oraconf.rb
Overview
module Logging
Defined Under Namespace
Classes: MiniRegistryError
Constant Summary collapse
- ERROR_SUCCESS =
I looked in Win32Module by MoonWolf <URL:www.moonwolf.com/ruby/>, copy the minimum code and reorganize it.
0
- ERROR_FILE_NOT_FOUND =
2
- HKEY_LOCAL_MACHINE =
0x80000002
- RegOpenKeyExA =
Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L')
- RegQueryValueExA =
Win32API.new('advapi32','RegQueryValueExA','LPPPPP','L')
- RegCloseKey =
Win32API.new('advapi32', 'RegCloseKey', 'L', 'L')
Instance Method Summary collapse
Instance Method Details
#get_local_registry(subkey, name) ⇒ Object
UNIX
90 91 92 |
# File 'ext/oci8/oraconf.rb', line 90 def get_local_registry(subkey, name) get_reg_value(HKEY_LOCAL_MACHINE, subkey, name) end |
#get_reg_value(root, subkey, name) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/oci8/oraconf.rb', line 57 def get_reg_value(root, subkey, name) result = [0].pack('L') code = RegOpenKeyExA.call(root, subkey, 0, 0x20019, result) if code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegOpenKeyExA", code) end hkey = result.unpack('L')[0] begin lpcbData = [0].pack('L') code = RegQueryValueExA.call(hkey, name, nil, nil, nil, lpcbData) if code == ERROR_FILE_NOT_FOUND return nil elsif code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegQueryValueExA",code) end len = lpcbData.unpack('L')[0] lpType = "\0\0\0\0" lpData = "\0"*len lpcbData = [len].pack('L') code = RegQueryValueExA.call(hkey, name, nil, lpType, lpData, lpcbData) if code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegQueryValueExA",code) end lpData.unpack('Z*')[0] ensure RegCloseKey.call(hkey) end end |