Visual Basic Registry Editing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Visual Basic Registry Editing

  1. #1
    Join Date
    Nov 2003
    Posts
    4

    Exclamation Visual Basic Registry Editing

    Hello All

    I was hoping somebody could tell how to delete a key and a value from the registry but not at the same time i.e seperate programs.

    When I searched elsewhere I only found masses of buggy code and I was just wondering if anyone could give me some very simple code to do this.

    Thanks in advance

    rocket24

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    ...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.

  3. #3
    Join Date
    Nov 2003
    Posts
    4
    Thanks for replying so quickly.

    When I downloaded your program I can enumarte all registry keys but no values. When I look at the source code I can see the extra buttons such as delete values but can not see them when I run the program. When looking at the source they do not have any code attached to them either.

    I noticed it worked for another user. Maybe it is just me.

    Do you know why?

    Thanks

    rocket24

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

    Here...

    Now, this is an example, but beware: it will delete keys and values, if you press the buttons...

    To use it:
    You have to choose a registry Root from Combo.
    Then you should provide a registry key or press the "Enum Subkeys" button - in this second case, you can then select one from listbox, press Ctrl+C and paste in the registry Key textbox.
    If you need to go deeper, you can now press the enum subkeys once more, and then repeat the above, adding the last key to the previous one with a "\" (ie: combo value: Hkey_current_user;
    key txt value: AppEvents\EventLabels)
    Once you are on the desired key you could delete it. Or you could press the Enum Values button to see
    Value(=identifier)Name and Value Data.
    Inserting the value name in the Value Txt will allow you to delete
    that value - This will delete BOTH the value NAme and the value Data. To "Blank" only the value data, you should not delete, but simply change its value...
    Attached Files Attached Files
    Last edited by Cimperiali; November 22nd, 2003 at 04:17 AM.
    ...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.

  5. #5
    Join Date
    Nov 2003
    Posts
    4
    Thanks that one works.

    Do you know if there is simpler code to create, modify or delete values or keys with the need of modules?

    All the code I have found on the net is similar to yours with Case Selects etc and not just a simple command button not linked to anything else.

    Any help appreciated

    Thanks

  6. #6
    Join Date
    May 2002
    Location
    Montreal
    Posts
    450
    Not sure what you are trying to accomplish but the easiest way to store and retrieve data to and from the registry is to use SaveSetting and GetSetting

    SaveSetting appname, section, key, setting

    GetSetting(appname, section, key[, default])


    All goes to
    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Your application

    Just provide a name, a section and the key name and value
    hth
    Cheers,
    Laurent

    For an aviator, the three best things in life are a good landing, a good orgasm, and a good sh*t. A night carrier landing is one of the few opportunities to experience all three at the same time.

  7. #7
    Join Date
    Nov 2003
    Posts
    4
    Im just curious

    Thanks

  8. #8
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,922
    If you are curious, there is another method. WshShell object have the following method RegRead, RegWrite and RegDelete. It prevents you from using a tons of API, but at the same time, you'll need to add the reference to Windows Script Host Model, anyway, here is a small example, it is the equivalent of the module using API:


    Code:
    Private Sub Command1_Click()
        'Add a reference to Windows Script Host Model
        Dim objReg As New WshShell
        Dim strKey As String
         
        'This key will be created by SaveSetting in a second
        strKey = "HKEY_USERS\.DEFAULT\Software\VB and VBA Program Settings\REGTEST\TESTSECTION\TESTKEY"
         
        'This save the settings to the registry at a specific VB key
        SaveSetting "REGTEST", "TESTSECTION", "TESTKEY", "Test Value"
         
        'It read that specific VB Key
        MsgBox objReg.RegRead(strKey), , "We just set this value with SaveSetting"
         
        'Now it overwrite the value
        objReg.RegWrite strKey, "Test Value modified by RegWrite"
         
        'Read it again
        MsgBox objReg.RegRead(strKey), , "Value using WshShell.RegRead"
        MsgBox GetSetting("REGTEST", "TESTSECTION", "TESTKEY"), , "Value with GetSetting"
         
        'Now Delete the Key, notice I delete the whole section and not just the key
        objReg.RegDelete "HKEY_USERS\.DEFAULT\Software\VB and VBA Program Settings\REGTEST\"
         
        'Read it again, but it don't exist anyway
        MsgBox objReg.RegRead(strKey), , "This line return an error"
    
    
        Set objReg = Nothing
    End Sub
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

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

    Really NIce!

    Nice!

    see you on the web

    Cesare
    Last edited by Cimperiali; November 22nd, 2003 at 04:12 AM.
    ...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.

  10. #10
    Join Date
    Apr 2002
    Location
    WA
    Posts
    34

    Something wrong on Windows 2000 Server

    I found something else on Windows 2000 Server with WshShell object as . The App accessed the registry run-time, and the error occirred in only windows 2000 Server. I found some articles that said 'missing component'. I am not sure it is true. I have tested reliable cabinet file deployment, but I got the same error.
    Have you run some Apps which has WshShell with Registry Access? Did you got the error 429?
    Please let me know.
    Thanks a lot
    Thanks,

    --- nicepat

  11. #11
    Join Date
    Jun 2004
    Posts
    2
    Is there a way of getting Visual Basic to completely erase a part of the registry?

    For example, I have a key at HKEY_CURRENT_USER\Software\AAA Software\DefaultSettings\Top which has a value of 1.

    I want to totally delete (not over-write) everything under HKEY_CURRENT_USER\Software\AAA so that it doesn't exist anymore. I may not know every sub key, so I can't do each bit individually.

    I've tried the code at http://www.codeguru.com/forum/showth...postid=848248, I've tried Microsoft's suggestion of using WshShell and I've tried a program found on this forum (playregistry) but none will delete what I'm looking for

  12. #12
    Join Date
    Jun 2004
    Posts
    15

    um ?

    Um .... It says: User-defined type not defined
    and it highlights: objReg As New WshShell
    so ?

  13. #13
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,209
    Um .... It says: User-defined type not defined
    click Project->References->check (windows script host Object model)
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center