Module: MiniRegistry
- Defined in:
- ext/oci8/oraconf.rb
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- ERROR_NO_MORE_ITEMS =
259- HKEY_LOCAL_MACHINE =
0x80000002- KEY_ENUMERATE_SUB_KEYS =
0x0008- KEY_QUERY_VALUE =
0x0001- RegOpenKeyExA =
Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L')
- RegEnumKeyExA =
Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPPPPP', 'L')
- RegQueryValueExA =
Win32API.new('advapi32','RegQueryValueExA','LPPPPP','L')
- RegCloseKey =
Win32API.new('advapi32', 'RegCloseKey', 'L', 'L')
Class Method Summary collapse
Class Method Details
.enum_homes ⇒ Object
52 53 54 55 56 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 52 def self.enum_homes phkResult = [0].pack('L') code = RegOpenKeyExA.call(HKEY_LOCAL_MACHINE, 'SOFTWARE\ORACLE', 0, 0x20019, phkResult) if code != ERROR_SUCCESS raise MiniRegistryError.new("Win32::RegOpenKeyExA", code) end hKey = phkResult.unpack('L')[0] idx = 0 maxkeylen = 256 loop do lpName = "\0" * maxkeylen lpcName = [maxkeylen].pack('L') code = RegEnumKeyExA.call(hKey, idx, lpName, lpcName, nil, nil, nil, nil); break if code == ERROR_NO_MORE_ITEMS if code != ERROR_SUCCESS RegCloseKey.call(hKey) raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end code = RegOpenKeyExA.call(hKey, lpName, 0, KEY_QUERY_VALUE, phkResult) if code != ERROR_SUCCESS RegCloseKey.call(hKey) raise MiniRegistryError.new("Win32::RegEnumKeyEx", code) end hSubkey = phkResult.unpack('L')[0] name = get_str_value(hSubkey, 'ORACLE_HOME_NAME') path = get_str_value(hSubkey, 'ORACLE_HOME') yield name, path RegCloseKey.call(hSubkey) idx += 1 end RegCloseKey.call(hKey) end |
.get_str_value(hKey, name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'ext/oci8/oraconf.rb', line 33 def self.get_str_value(hKey, name) 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].pack('L') 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] end |