Link to home
Start Free TrialLog in
Avatar of triphen
triphen

asked on

VB6 reading registry in Win7+

Hello Experts,

I have an application that is supposed to read a registry key and populate a label with it's value. Here is the code:

 Dim oReg As Object
    Set oReg = CreateObject("WScript.Shell")
    lbl_LMIName.Caption = oReg.RegRead("HKLM\Software\LogMeIn\V5\WebSvc\" & "HostDescription")
    Set oReg = Nothing

Open in new window


It works perfect on WinXP but all other OS (7, 2008, 2012) it throws this error:

---------------------------
RemoteSupportUpdater
---------------------------
Run-time error '-2147024894 (80070002)':

Invalid root in registry key "HKLM\Software\LogMeIn\V5\WebSvc\HostDescription".
---------------------------
OK  
---------------------------

But the path does exist in the registry. Any ideas on what I am doing wrong?
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

This could be a permissions error. Try running your script by right clicking and using "Run as Administrator"
Avatar of triphen
triphen

ASKER

Sorry for delayed response. Yes I have tried that. Same problem
Would I be right in guessing that the 7, 2008, 2012 machines are x64 whereas the XP machine is x32.

If this is correct then what is happening is that when using a 32 bit application on x64 machine you get redirected to the Wow6432Node key by default.
https://msdn.microsoft.com/en-us/library/aa384129(v=vs.85).aspx
This registry handler could help you you here.

http://www.freevbcode.com/ShowCode.asp?ID=1519
Avatar of triphen

ASKER

Sorry for the delay. Was in the hospital :/

Thanks for this. I am using

Public Function GetRegValue(RootKey As HKEYS, sKey As String, sValueName As String) As Variant
    Dim hKeyHandle As Long
    Dim vTemp As Variant
    Call RegOpenKeyEx(RootKey, sKey, 0&, lngKEY_ALL_ACCESS, hKeyHandle)
    ReadRegistryValue hKeyHandle, sValueName, vTemp
    Call RegCloseKey(hKeyHandle)
    GetRegValue = vTemp
End Function

Open in new window


GetRegValue("HKEY_LOCAL_MACHINE", "Software\LogMeIn\V5\WebSvc", "HostDescription")

But it errors with "Type Mismatch"
ASKER CERTIFIED SOLUTION
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of triphen

ASKER

Nice, thank you!

Now a new problem....I get Runtime -7 "Out of memory" when running on Server 2008 or Server 2012. Works fine on XP and 7.
hmm not sure. This could be permissions, try running the script with "Run as an Administrator" even if you are logged in with Admin rights.
Avatar of triphen

ASKER

Still no good. I will open a new question. Thanks!