How to read Registry

Hi,

I need to read a registry information about Oracle installation, so I’ve tried to use below code but I just see that reg.KeyCount is 0.
Actually, there are 3 items under KEY_OraClient11g_home1 folder.

dim reg as new registryitem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1”)
//reg =reg.child(“KEY_OraClient11g_home1”)

Dim lines() As String
Dim found As Boolean

MsgBox " reg.KeyCount : " + str(reg.KeyCount)

Can anyone let me know how to read that registry correctly?

Thanks in advance,
Changwon.

Are they Folders, or Keys?

Folders are on the left pane in RegEdit. Keys are in the right pane.

[quote=177181:@changwon lee]Hi,

I need to read a registry information about Oracle installation, so I’ve tried to use below code but I just see that reg.KeyCount is 0.
Actually, there are 3 items under KEY_OraClient11g_home1 folder.

dim reg as new registryitem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1”)
//reg =reg.child(“KEY_OraClient11g_home1”)

Dim lines() As String
Dim found As Boolean

MsgBox " reg.KeyCount : " + str(reg.KeyCount)

Can anyone let me know how to read that registry correctly?
[/quote]

Are you sure there are keys within HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1 ? First thing to do is to use Regedit to check the structure, and see what is there. Then you will clearly know what is or not in there and be able to modfy your code accordingly.

Yes there are 3 keys in the right pane, and I can see those ones as follows in regedit.

ORACLE_GROUP_NAME : Oracle - OraClient11g_home1
ORACLE_HOME : C:\app\clee2\product\11.2.0\client_1
ORACLE_HOME_NAME : OraClient11g_home1

For some other folders, I’m able to read the registry key information through the code above, but for some folders, I can’t.
I think this is related to registry permission.
However, even though I ran my application with administrator and put the all privileges on the folder, I got the same issue.

I’m not sure there is special consideration in handling registry information in Xojo.

[quote=177192:@changwon lee]Yes there are 3 keys in the right pane, and I can see those ones as follows in regedit.

ORACLE_GROUP_NAME : Oracle - OraClient11g_home1
ORACLE_HOME : C:\app\clee2\product\11.2.0\client_1
ORACLE_HOME_NAME : OraClient11g_home1

For some other folders, I’m able to read the registry key information through the code above, but for some folders, I can’t.
I think this is related to registry permission.
However, even though I ran my application with administrator and put the all privileges on the folder, I got the same issue.

I’m not sure there is special consideration in handling registry information in Xojo.[/quote]

Unless a key has the same name as the containing folder, you were trying to look for keys inside a key. You need to go up a level to the path on the left that contains your three keys.

Then all you probably need to do is to look for your keys inside :

HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE\\

In the left pane,
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1
For the KEY_OraClient11g_home1 folder, it has 3 keys in right pane like below.
ORACLE_GROUP_NAME
ORACLE_HOME
ORACLE_HOME_NAME
And, these ones have its own value.

Of course, I’ve tried to use below one but zero value of reg.KeyCount.
dim reg as new registryitem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE”)

If Oracle is installed in your environment, can you try to access the registry information?

If you are using a 64-bit version of Windows then I think Xojo only accesses keys under the …\Wow6432Node\… key

https://forum.xojo.com/2748-reading-64bit-registry-keys

refers to this.

Great. Yes you’re right.
dim reg as new registryitem(“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_OraDb11g_home1”)

I am able to get the all key values there.

Thank you so much!

[quote=177204:@Chris Carter]If you are using a 64-bit version of Windows then I think Xojo only accesses keys under the …\Wow6432Node\… key

https://forum.xojo.com/2748-reading-64bit-registry-keys

refers to this.[/quote]

That is strange. I am accessing the keys within HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\kbdclass\Enum in my latest app under Windows 10 Pro 64 bit, as well as Windows 8.1 Pro 64 bit without any special difficulty.

I looked at my Win 10 registry structure in Regedit, and as far as I can tell, only Apple and Microsoft seem to place anything under Wov6432Node in HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE\Wow6432Node. Oracle\VirtualBox is not under any Wow6432Node.

At any rate, thank you for the tip. Will remember it in case I encounter a strange behavior there.

[quote=177212:@changwon lee]dim reg as new registryitem(“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_OraDb11g_home1”)

I am able to get the all key values there.[/quote]

er, not exactly what I was getting at… I believe Xojo always uses that Wow6432node anyway, what is harder is looking at values stored outside (IE: values for 64.bit apps) …

Are you sure it is not that you had success looking for the value name “KEY_OraDb11g_home1” which I cannot see amongst the ones you mentioned earlier ? ( They had ...OraClient... not ...OraDb... )

There are several child folders under the initial RegistryItem, so I needed to parse it more like below.
A little bit messy but it works well for my requirement to get the ORACLE_HOME value.

#If Target64Bit Then
dim reg as new RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE”)
#Endif

#If Target32bit Then
dim reg as new RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE”)
#Endif

dim tryreg as RegistryItem
dim folders() as string
dim i as integer
dim path As String
Dim getORACLE_HOME As String

for i= 0 to reg.FolderCount-1

folders.append reg.item(i).path

If InStr(folders(i), "KEY_Ora") > 0 Then
 
  path = folders(i)
  tryreg = New RegistryItem(path)
  
  for i= 0 to tryreg.KeyCount- 1
     If tryreg.name(i) = "ORACLE_HOME" Then
      getORACLE_HOME = tryreg.value(i)
      Return getORACLE_HOME
    End If
  next
  
End If

next

[quote=177229:@Michel Bujardet]That is strange. I am accessing the keys within HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\kbdclass\Enum in my latest app under Windows 10 Pro 64 bit, as well as Windows 8.1 Pro 64 bit without any special difficulty.

I looked at my Win 10 registry structure in Regedit, and as far as I can tell, only Apple and Microsoft seem to place anything under Wov6432Node in HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE\Wow6432Node. Oracle\VirtualBox is not under any Wow6432Node.[/quote]

I believe 32.bit apps use Wow6432Node by default in 64.bit windows O/Ss for HKEY_LOCAL_MACHINE and probably the USER ones
There is a flag in the API to override it, but that is not (yet) and option in XOJO.

Looks like HKEY_CLASSES_ROOT behaves differently !

Further to the above…

If I try to access “HKEY_LOCAL_MACHINE\SOFTWARE\MyTest”
it does not find it there, but does find it in “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyTest”
on a 64.bit system.

If I try to access a value under HKEY_CLASES_ROOT\MyTest
it finds it there OK (!)

[quote=177233:@changwon lee]#If Target64Bit Then
dim reg as new RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE”)
#Endif

#If Target32bit Then
dim reg as new RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE”)
#Endif[/quote]

I’d be very happy to be proved wrong, but applications built for windows are still always 32 bit executables.

These #if... blocks are compile time, rather that run time, tests.

I do not believe you are ever using the #if Target64 path.

Oh Thanks for your comment on #ifTarget64.
I’m a newbie in Xojo. Just expert in other world…^.

[quote=177239:@changwon lee]Oh Thanks for your comment on #ifTarget64.
I’m a newbie in Xojo. Just expert in other world…^.[/quote]

Glad to have been of some help.

How to check if Windows is 64bit:

  #If TargetWin32 Then
    Soft Declare Function GetCurrentProcess Lib "kernel32"  As Integer
    Dim processID As Integer
    processID = GetCurrentProcess
    
    Soft Declare Function IsWow64Process Lib "kernel32" (handle As Integer, ByRef result As Boolean) As Integer
    
    If System.IsFunctionAvailable( "IsWow64Process", "Kernel32" ) Then
      
      Dim value As Boolean
      Call IsWow64Process(processID, value)
      
      if value Then
        return True
      else
        return False
      end if
    End If
  #Endif
  
  return False

[quote=177296:@Ashot Khachatryan]How to check if Windows is 64bit:

[code]
#If TargetWin32 Then
Soft Declare Function GetCurrentProcess Lib “kernel32” As Integer
Dim processID As Integer
processID = GetCurrentProcess

Soft Declare Function IsWow64Process Lib "kernel32" (handle As Integer, ByRef result As Boolean) As Integer

If System.IsFunctionAvailable( "IsWow64Process", "Kernel32" ) Then
  
  Dim value As Boolean
  Call IsWow64Process(processID, value)
  
  if value Then
    return True
  else
    return False
  end if
End If

#Endif

return False
[/code][/quote]

Thank you Ashot :slight_smile:

If you are not sure if the registry item exists on a system, be sure to pass the optional CREATE flag to New RegistryItem. Otherwise it will try to create the item.

dim reg as RegistryItem
Try
   reg = new RegistryItem("HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE\", FALSE)
Catch e as RegistryAccessErrorException
   // doesn't exist
End

Tim Hare,

In case there is no Oracle client(registry information), below code got RegistryAccessErrorException.

[code] dim reg as RegistryItem

Try
'RegistryItem.Constructor(path as String , create as Boolean)
reg = new RegistryItem(“HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE”, TRUE)
Catch e as RegistryAccessErrorException
MsgBox “Registry information doesn’t exist”
Return “NO”
End
[/code]

I just want to let user know the fact that there is no oracle.
Can you please let me know how to do it?