Visual Basic
  Home arrow Visual Basic arrow Page 3 - Registry Fever With Visual Basic
eWeek
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC

Registry Fever With Visual Basic
By: Neville Mehta
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 47
    2002-12-20

    Table of Contents:
  • Registry Fever With Visual Basic
  • Why The Registry?
  • The DeleteSetting Function
  • Using the Windows API To Access the Registry
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Registry Fever With Visual Basic - The DeleteSetting Function
    (Page 3 of 5 )

    The DeleteSetting function allows us to delete any value/values from the registry. The signature of the DeleteSetting function looks like this:

    DeleteSetting <ApplicationName> [,<Section> [,<Key>]]

    Application Name: The application name from which we are deleting keys
    Section: Contains the keys you need to delete. This is an optional parameter
    Key: The name of the key that you want to delete. This is an optional parameter

    Private Sub DeleteRegistry()
    DeleteSetting "TestApp"
    DeleteSetting "TestApp2", "TestSection2"
    DeleteSetting "TestApp3", "TestSection3", "TestKey3"
    End Sub


    Let's see exactly what the code above does:

    Firstly, it would delete the entire TestApp key (including all sub-keys and values) under it from the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TestApp path.

    Next, it would delete the entire TestSection2 key (which is a part of the TestApp2 key) and all sub-keys and values under it from the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TestApp2\TestSection2 path. However, the TestApp2 key and its contents wouldn’t be deleted.

    Finally, it would delete the TestKey3 string value (which is a part of the TestApp3\TestSection3 keys). However the TestApp3 key and TestSection3 key (and their contents) wouldn't be deleted.

    The GetAllSettings Function
    The GetAllSettings function allows us to retrieve an entire collection of string values from the registry. Using this function, we can retrieve an entire set of string values from a particular section. The signature for the GetAllSettings function looks like this:

    GetAllSettings (<ApplicationName>, <Section>)

    Application Name: The application key under which you need to retrieve the collection of string values
    Section: The key to where the collections of values are present

    Private Sub GetAllRegistry()
    Dim valuesandkeys As Variant
    Dim count As Integer

    SaveSetting "Tester", "TestSec", "TestName1", "TestVal1"
    SaveSetting "Tester", "TestSec", "TestName2", "TestVal2"

    valuesandkeys = GetAllSettings("Tester", "TestSec")

    For count = LBound(valuesandkeys) To UBound(valuesandkeys)
    Key = valuesandkeys(count, 0)
    value = valuesandkeys(count, 1)
    MsgBox Key
    MsgBox value
    Next count
    End Sub


    Let's see exactly what the code above does:

    Firstly, we add two string values into the registry under the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Tester\TestSec\ path.

    Next, we call the GetAllSettings function which returns a two dimensional array of all keys and values in the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Tester\TestSec\ hive.

    Finally, we use a simple for loop to display all of the values in the array. The first index in the array holds the name/key serial count. We would pass 0 as the next index if we wanted to display the string name and 1 if we wanted to trap the key string value. The structure of the two dimensional array looks like this:

         0     1
    0     TestName1     TestValue1
    1     TestName2     TestValue2

    Thus, if we pass the index 1,1 to the array, then it would return "TestValue2". If we pass the index 0,0 to the array then it would return "TestName1".

    There are some points to remember when using Visual Basic functions to access the registry:
    1. This code wouldn't work if you didn’t have appropriate permissions to access the registry. Remember, whenever you run software on a computer that interacts with the registry, you have to make sure the logged in user has privileges to access the system registry or else your program will not function.
    2. The Visual Basic functions help us interact with the registry only under the following path "HKEY_CURRENT_USER\Software\VB and VBA Program Settings"..
    3. The Visual Basic functions are capable of retrieving and setting String keys only.
    As you can see, there are some disadvantages to using Visual Basic's registry functions. For example, what if you needed to set/retrieve values from other parts of the registry? What if you need to set/retrieve binary or dword values from the registry? Well, in such cases you may have to use the Windows API to access the registry, which is what we will look at next.

    More Visual Basic Articles
    More By Neville Mehta


     

    VISUAL BASIC ARTICLES

    - Developing an XML Web Service Using Visual S...
    - Creating an HTML File List with VB
    - Fun with Email: VB6, CDO, MAPI, and a Remote...
    - Extranet/Intranet Dictionary Cracker in VB
    - Finding Default App Icons With Visual Basic
    - Registry Fever With Visual Basic
    - Implementing An ADO Data Control With VB6
    - Printing With Visual Basic
    - MSMQ Part 1/2: Architecture and Simple Imple...
    - Magnifying The Desktop With Visual Basic
    - Sending Email With MAPI Components in Visual...
    - Two Person Chat With The Winsock Control And...
    - A Real-Time ActiveX News Control
    - Accessing the Windows API in Visual Basic






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway