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?
triphenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael FowlerSolutions ConsultantCommented:
This could be a permissions error. Try running your script by right clicking and using "Run as Administrator"
triphenAuthor Commented:
Sorry for delayed response. Yes I have tried that. Same problem
Michael FowlerSolutions ConsultantCommented:
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Michael FowlerSolutions ConsultantCommented:
This registry handler could help you you here.

http://www.freevbcode.com/ShowCode.asp?ID=1519
triphenAuthor Commented:
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"
Michael FowlerSolutions ConsultantCommented:
You are entering RootKey as a string value when the method is expecting it to be an enum HKEYS

Enum HKEYS
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
End Enum

Open in new window


So change your method call to

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

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
triphenAuthor Commented:
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.
Michael FowlerSolutions ConsultantCommented:
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.
triphenAuthor Commented:
Still no good. I will open a new question. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.