|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Reading from and Writing to the Registry Using My
The My.Computer.Registry object offers methods and properties for working with registry keys.
The Windows registry hosts information from the operating system as well as information from applications hosted on the computer. Although My.Settings is recommended for storing such information, legacy applications may make use of the registry.
For a complete list of the My.Computer.Registry members, see My.Computer.Registry Object Members.
The following table lists examples of tasks for registry keys involving the My.Computer.Registry object.
Create a registry key
Delete a registry key
Determine whether a value exists
Read a value
Working with the registry may compromise security by allowing inappropriate access to system resources or protected information. To use these properties, you must have read and write permissions from the RegistryPermissionAccess enumeration, which controls access to registry variables. Any code running with full trust (under the default security policy, this is any code installed on the user's local hard disk) has the necessary permissions to access the registry. For more information, see RegistryPermission class.
Registry variables should not be stored in memory locations where code without RegistryPermission can access them. Similarly, when granting permissions, grant the minimum privileges necessary to get the job done.