Visual Basic
  Home arrow Visual Basic arrow Page 2 - Registry Fever With Visual Basic
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  
Mobile Linux 
App Generation ROI 
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 / 51
    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
     
     
    ADVERTISEMENT


    Registry Fever With Visual Basic - Why The Registry?


    (Page 2 of 5 )

    In the olden days (and sometimes even now), most of the user related information was stored in INI files. The INI file stored data in a name/value format. Then, these values were set and retrieved from the INI files whenever required. The INI file is easy to read via a normal text editor. Here is an example of a standard INI file:

    ; This is a comment
    [Category]
    Name1=Value1
    Name2= Value2

    The INI file looks quite self-explanatory. The first line is a comment. Notice how a semicolon precedes it? The second line is the category name. Notice how its enclosed within "[" brackets. Finally, we have the name/value data on the third and fourth line.

    A few drawbacks of storing data in "profiles" (which is another name for INI files) include:
    • There wasn't any central database where data was stored as each program had its own INI file in its respective directory.
    • Setting and retrieving values from these files was quite an inefficient task. They weren't organized in anyway.
    These aspects lead to creation of the registry.

    What Is The Registry?
    The registry is a hierarchical database. Its similar to the directory structure you see in Windows explorer. The registry consists of various hives and keys. You could navigate via the registry the same way you navigate through your Windows explorer. To open the windows registry on your Windows 9x pc, follow these steps:
    • Click on Start -> Run
    • Enter "regedit" in the text box
    • Click "OK"
    If all goes right then you will see the Windows registry, which looks like this:



    The registry stores information in different categories, which are known as hives. The folders appearing on the left hand side of the registry are all hives. A hive may be further divided into keys. All of the information in the registry is divided into 6 major categories (or hives). Each hive may contain multiple keys and those keys may contain multiple sub-keys. Now let's look at what information these different hives (or categories) contain:

    1. HKEY_CLASSES_ROOT
    Stores information about the DLL's on the current computer. It also stores information about file extensions.

    2. HKEY_CURRENT_USER
    Stores information about the user who is currently logged on to the computer. Information stored includes environment variables, desktop settings, network configuration, etc.

    3. HKEY_LOCAL_MACHINE
    Stores information about the hardware and software configuration on the computer.

    4. HKEY_USERS
    Stores information about all users registered on the computer. Information stored includes environment variables, desktop settings, network configuration, etc.

    5. HKEY_CURRENT_CONFIG
    Stores information about the current hardware and software configuration on the computer.

    6. HKEY_DYN_DATA
    Stores information that changes frequently (dynamic information) on your computer. This includes thread/process details, plug and play, etc.

    Functions To Access The Registry
    You can access the registry a number of ways in Visual Basic. One of the ways is to use functions for interacting with the registry.

    The SaveSetting Function
    The SaveSetting function allows us to store any value in the registry. The functions signature looks like this:

    SaveSetting <ApplicationName>, <Section>, <Key>, <Value>

    Application Name: The name of the application that's creating the key
    Section: The section name under which this key is being created.
    Key: The name of the key being created
    Value: The value of the key being created

    The following code snippet would add a key called TestKey in the registry to the HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TestApp\TestSection path:

    SaveSetting "TestApp", "TestSection", "TestKey", "TestVal"

    The GetSetting Function
    The GetSetting function allows us to retrieve any value from the registry. The usage of the GetSetting function looks like this:

    GetSetting (<ApplicationName>, <Section>, <Key>[, Default])

    Application Name: The application name for which we are retrieving this key
    Section: The section name under which this key is being stored
    Key: The name of the key that we are creating
    Default: The default value would be returned if the value of the key couldn't be retrieved. This is an optional parameter.

    The following code snippet would retrieve the value of the key TestKey from the registry under the following path HKEY_CURRENT_USER\Software\VB and VBA Program Settings\TestApp\TestSection path:

    Dim value As String
    value = GetSetting("TestApp", "TestSection", "TestKey", "Default")
    MsgBox value


    "Default" would be displayed if no such entry was found.

    More Visual Basic Articles
    More By Neville Mehta


       · We need a specific registry project like disabling Task manager or folder option.......
     

    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-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek