Results 1 to 11 of 11

Thread: [ Resolved]Read from registry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    [ Resolved]Read from registry

    Hello i need code how to read from registry.


    so for example i got HKEY_LOCAL_MACHINE\software\myapp\important\name


    So i need to read the value of "name" and write it on label


    ty
    Last edited by lulzoralot; Jul 6th, 2008 at 05:41 AM.

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Read from registry

    Hai Lulzorlot,

    I normally use API methods for reading form the registry.
    the api's are
    RegOpenKeyEx() - First you need to open that key HKEY_LOCAL_MACHINE\software\myapp\important\name
    RegQueryValueEx() - This api return that value you wanted.

    If you search the code bank of VBF, you have many examples there.

    Also, there are few vbnative function also to read and write to the reg. but i am not much with them

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Read from registry

    Those vbnative functions only read/write to the VB and VBA Programs Settings hive.

    GetSetting/SaveSetting

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Read from registry

    Yah rob,
    tx for remembering that.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    Re: Read from registry

    Hello i fuond this module.


    But how can i use it.I mean how can i read from registry

    i need to read value of HKEY_LOCAL_MACHINE\software\myapp\important\name

    ty
    Attached Files Attached Files

  6. #6
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Read from registry

    Attached is the class I wrote to deal with the registry. It would handle what you ask like this:
    Code:
    Public Sub Sample()
        Dim reg As clsRegistry
        Dim strName As String
    
        Set reg = New clsRegistry
        strName = reg.ReadString("Software\MyApp\Important", "Name", "", rrLocalMachine)
        Set reg = Nothing
        MsgBox strName
    End Sub
    Attached Files Attached Files

  7. #7
    Member sivagk's Avatar
    Join Date
    May 2003
    Location
    India
    Posts
    55

    Re: Read from registry

    this is my piece of code which I had used in my application and it is working fine...

    vb Code:
    1. Private Function RegKeyRead(strPath As String) As String
    2. Dim objCreate As Object
    3. Set objCreate = CreateObject("wscript.shell")
    4.  
    5. RegKeyRead = objCreate.RegRead(strPath)
    6.  
    7. End Function

    vb Code:
    1. Private Sub RegKeyWrite(strRegPath As String, strRegNewVal As String)
    2. Dim objCreate As Object
    3. Set objCreate = CreateObject("wscript.shell")
    4.  
    5. objCreate.RegWrite strRegPath, strRegNewVal, "REG_SZ"
    6.  
    7. End Sub

    Please note that if you give strRegPath as a new value which is not in Regedit, it will create the same and mainly this is for "REG_SZ".

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    Re: Read from registry

    Thanks guys it works

  9. #9
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Read from registry

    Quote Originally Posted by sivagk
    this is my piece of code which I had used in my application and it is working fine...
    How do you specify the hive? Note that the OP is trying to read from LOCAL_MACHINE, not CURRENT_USER.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [ Resolved]Read from registry

    Probably have to pass the entire path in the strPath argument.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Outlook

    or such I would assume from the look of it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: [ Resolved]Read from registry

    Ah, makes sense.

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