PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Registry-VBForums
Results 1 to 24 of 24

Thread: [RESOLVED] Registry

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Resolved [RESOLVED] Registry

    I would like to load some registry data into an array. IE, select a key 'SOFTWARE\Microsoft\Windows\' and load all the values into an array.

    thanks

    Simon Canning

  2. #2
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: Registry

    Simon

    Check the 9th post in this link... on how to get the names of all sub keys in the main key... you will have to amend it as per your requirements...

    Also here is a small function to read the value of the subkey when you know the subkey... once you get the subkey... you can always load it into an array which I am sure you won't have a problem with...

    vb Code:
    1. Private Sub Command1_Click()
    2.     MsgBox ReadFrmReg("HKEY_CURRENT_USER\Control Panel\Accessibility\StickyKeys\", "Flags")
    3. End Sub
    4. Private Function ReadFrmReg(KeyPath, SubKeyName) As Variant
    5.     Dim Registry As Object
    6.     Set Registry = CreateObject("WScript.Shell")
    7.     ReadFrmReg = Registry.RegRead(KeyPath & SubKeyName)
    8. End Function
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

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

    Re: Registry

    Which OS is this for? If Vista or 7 then you may need to run your app under Admin credientials.
    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

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    Its Xp pro.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    koolsid, the 9th post is what i am after.

    I want to do a recursive search with the keys returned and then have them added into an array.

    Can you (or someone else) help me with this?

    thanks

  6. #6
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,998

    Re: Registry

    Did you download that example and check it?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ
    MyGear:
    OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    yeh, i checked the example. It lists the key selected, but not the subkeys under it as well. That is what i am after. I have tried the code myself, but have had no luck.

    Is there some sample code out there to do this?

  8. #8
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Registry

    You can build recursive methods that will read the keys on a given level, collect the results, then pass them back to the outer method. As soon as there are no more sub-keys on the given level, the recursion will stop there, it will exit the loop, and let the outer instances, to collect the other subkeys from the upper levels.

    Here is a simple example how recursion can be implemented.

    Code:
    Function AddNumber() As Long
      AddNumber = AddNumber + 1
    End Function
    For sure, this will be an endless loop (as long as the execution didnt reach the upper limit of the Long value type), however this gives you the single idea how a recursive routine will work.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,669

    Re: Registry

    check this scripting method, you can of course do the same with API method

    http://www.vbforums.com/showthread.php?t=567903
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    Westconn1: I get an 'object required' at oreg.EnumKey hkey, strkeypath, arrsubkeys

    Is there a project with all the working code in it that I can have a look at?

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,669

    Re: Registry

    did you read the last line after the code box?
    declare oreg as object in the general section
    as the sub is recursive it makes more sense to only call getobject method once

    Is there a project with all the working code in it that I can have a look at?
    not really i just wrote it in the ide, i can get the code from codebank any time i want it
    Last edited by westconn1; Oct 25th, 2009 at 04:54 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    Code:
    declare oreg as object in the general section
    Can you give me the exact code to declare this, im a bit confused.

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,669

    Re: Registry

    dim oreg as object
    put that in the general section at the top of the code pane
    then it is available to all procedures in that code module, and will retain scope between procedures
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    i still get an error:
    Code:
    Object variable or with block variable not set
    at oreg.EnumKey hkey, strkeypath, arrsubkeys

    How can i fix this?

    thanks

  15. #15
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Registry

    0. use option explicit.

    1. declare oreg as object in the general section (at the declarations, at the top of your form's code)
    2. Set oreg = GetObject(....
    3. oreg.EnumKey hkey, strke ...

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    Code:
    2. Set oreg = GetObject(....
    , can you please explain this code line exactly.

  17. #17
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,646

    Re: Registry

    Code:

    2. Set oreg = GetObject(....

    , can you please explain this code line exactly.
    He is saying that you have to use the word Set before the line which begins with oreg = GetObject(

    Got it..??

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    yeh, got it.

    Thanks

  19. #19
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,646

    Re: Registry

    OK...

    If your problem is solved, mark this thread as RESOLVED (from Thread Tools in the top of this page). Also, you can rate the posts which helped you a lot...

    Good day...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  20. #20
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,669

    Re: Registry

    you have to call a recursive procedure with parameters, from some other procedure, i set the oreg object before calling the recursive sub, see the sample code in the 2nd procedure, which demonstrates how to call the main procedure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  21. #21

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    I am wanting to add all values returned to a string. What character should I use to seperate each key and value?

    Basically, I am after a character that will not appear in any registry entries... is there such a character?

  22. #22
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,669

    Re: Registry

    you can use vbnull or vbnullcharacter or even vbnewline would be unlikely
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    vbnull or vbnullcharacter wont work as they can appear in an item.

    Im thinking maybe non ascii characters. How do i create non ascii characters?

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Registry

    I might ask this in a new thread, as you have answered my first question.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width