CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2000
    Posts
    58

    HKEY_LOCAL_MACHINE and RegOpenKey

    Hi,

    I need to read value from HKEY_LOCAL_MACHINE.
    Same code works for HKEY_CURRENT_USER. Anybody knows whats is going on? Thanks for help.

    Function call

    DAAPath = GetRegEntry(HKEY_LOCAL_MACHINE, "\Software\Test", "DAA2000")

    '---------------------------------------------
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (byval hkey as Long, byval lpSubKey as string, phkResult as Long) as Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (byval hkey as Long, byval lpValueName as string, byval lpReserved as Long, lpType as Long, lpData as Any, lpcbData as Long) as Long
    Declare Function RegCloseKey Lib "advapi32.dll" (byval hkey as Long) as Long

    public Const ERROR_SUCCESS = 0&

    public Const HKEY_CLASSES_ROOT = &H80000000
    public Const HKEY_CURRENT_USER = &H80000001
    public Const HKEY_LOCAL_MACHINE = &H80000002
    public Const HKEY_USERS = &H80000003
    public Const HKEY_PERFORMANCE_DATA = &H80000004
    public Const HKEY_CURRENT_CONFIG = &H80000005
    public Const HKEY_DYN_DATA = &H80000006


    Function GetRegEntry(RootKey as Long, SubKeyName as string, KeyEntry as string) as string

    If RegOpenKey(RootKey, SubKeyName, hkey&) = ERROR_SUCCESS then
    Returned$ = Space$(255)
    Success& = RegQueryValueEx(hkey&, KeyEntry, 0&, lpType&, byval Returned$, 255)
    Returned$ = Trim$(Returned$)
    If (Returned$ <> "") then
    GetRegEntry = Left$(Returned$, len(Returned$) - 1)
    End If
    RegCloseKey (hkey&)
    End If

    End Function





  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: HKEY_LOCAL_MACHINE and RegOpenKey

    Cakkie answered something like this: you must have permissions to access the machine key. You can test this running regedit and trying to manually add a key to the HKEY_LOCAL_MACHINE. I am afraud you ewill have to relog as local administrator to be enabled...


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured