Program | Registry read the version of the program from the registry
Banhai (Sunhai)
Development tools: Microsoft Visual Studio. NET 2003
Operating system: Windows XP
Introduction to the Registry class
With Visual Studio. NET read-write registry typically uses the Registry class.
The Registry class provides a standard set of root items found in the registry on computers running Windows.
The registry is a storage device that contains information about applications, users, and default system settings. For example, an application can use the registry to store information that needs to be retained after the application shuts down and access those same information as the application reloads. For example, you can store color preferences, screen locations, or window sizes. By storing information in different locations in the registry, you can control this information for each user.
The base (root) RegistryKey instance exposed by Registry describes the basic storage mechanism for subkeys and values in the registry. All items are read-only because the registry relies on their presence. The items exposed by Registry are: CurrentUser stores information about user preferences. LocalMachine stores configuration information for the local computer. Classesroot stores information about types (and classes) and their properties. The users store information about the default User configuration. PerformanceData the performance information for the storage software component. Currentconfig stores hardware information that is not user specific. DynData store Dynamic Data.
Once you have identified the root entry under which you want to store/retrieve information in the registry, you can use the RegistryKey class to add or remove subkeys and manipulate the values of the given item.
Hardware devices can use a Plug and Play interface to automatically place information in the registry. Software that installs device drivers can place information in the registry by writing to the standard API.
RegistryKey class
The RegistryKey class represents an item-level node in the Windows registry. This class is a registry wrapper.
The registry acts as a central repository of information for the operating system and applications on your computer. The registry organizes hierarchically (for base-level items in the hierarchy, see Registry), based on the logical order in which the elements are stored. When storing information in the registry, select the appropriate location based on the type of information stored. Be sure to avoid damaging information that is created by other applications because it can cause unexpected behavior in those applications and adversely affect your own application.
Registrykeys is the basic organizational unit in the registry, like a folder in Windows Explorer. A specific item can have subkeys (as a folder can have subfolders), and can be deleted as long as the user has the appropriate DELETE permission and the item is not the base item or the next level item of the base item. Each item can also have more than one associated value (a value like a file) that stores information about the application you are interested in. Each value holds a specific piece of information that can be retrieved or updated when needed. For example, you can create a RegistryKey for your company (under item HKEY_LOCAL_MACHINE\Software), and then create a subkey for each application that your company creates. Each subkey holds information specific to the application, such as color settings, screen location and size, or a recognized file name extension.
Note that the information stored in the registry can be used by other applications and users, so do not use the registry to store security information or critical application information.
To get an instance of RegistryKey, either use a static member OpenSubKey or use a static member of the Registry class.
This article mainly uses the following:
Registrykey.opensubkey method: Retrieves the specified subkey with the specified write access permission.
Retrieves the subkey as read-only.
[Visual Basic] Overloads public Function OpenSubKey (String) as RegistryKey
Registrykey.getsubkeynames method: Retrieves an array of strings containing the names of all the subkeys.
Public Function getsubkeynames () as String ()
To read the version of Excel from the registry
Introduce namespaces first:
Imports System
Imports Microsoft.Win32
To get an idea of the registry, know where we're going to read it in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office.
Dim RK as RegistryKey = _
Registry.LocalMachine.OpenSubKey ("Software\Microsoft\Office", True)
' Get the ' data from a specified item in the key.
Dim s as String () = RK. Getsubkeynames ()
Dim Blnexcel as Boolean = False ' This machine installs Excel
Dim excelver as String ' Excel version number
For num as Integer = 0 to S.length-1
Select case S.getvalue (num)
Case "11.0", "9.0", "8.0", "5.0", "4.0", "3.0" ' Excel version number
Dim Rk1 as RegistryKey = _
Registry.LocalMachine.OpenSubKey ("Software\microsoft\office\" & S.getvalue (num) & "\excel", True)
If not (Rk1 are nothing) Then
Blnexcel = True
Excelver = S.getvalue (num)
Exit Select
Exit for
End If
End Select
Next
Is it easy to read and write the registry using the RegistryKey class?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service