How to: Read a Value from a Registry Key - Visual Basic (2024)

  • Article

The GetValue method of the My.Computer.Registry object can be used to read values in the Windows registry.

If the key, "Software\MyApp" in the following example, does not exist, an exception is thrown. If the ValueName, "Name" in the following example, does not exist, Nothing is returned.

The GetValue method can also be used to determine whether a given value exists in a specific registry key.

When code reads the registry from a Web application, the current user is determined by the authentication and impersonation that is implemented in the Web application.

To read a value from a registry key

  • Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.

    Dim readValue = My.Computer.Registry.GetValue( "HKEY_CURRENT_USER\Software\MyApp", "Name", Nothing)MsgBox("The value is " & readValue)

This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Windows Operating System > Registry. For more information, see Code Snippets.

To determine whether a value exists in a registry key

  • Use the GetValue method to retrieve the value. The following code checks whether the value exists and returns a message if it does not.

    If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\TestApp","TestValue", Nothing) Is Nothing Then MsgBox("Value does not exist.")End If

Robust Programming

The registry holds top-level, or root, keys that are used to store data. For instance, the HKEY_LOCAL_MACHINE root key is used for storing machine-level settings used by all users, while HKEY_CURRENT_USER is used for storing data specific to an individual user.

The following conditions may cause an exception:

.NET Framework Security

To run this process, your assembly requires a privilege level granted by the RegistryPermission class. If you are running in a partial-trust context, the process might throw an exception due to insufficient privileges. Similarly, the user must have the correct ACLs for creating or writing to settings. For example, a local application that has the code access security permission might not have operating system permission. For more information, see Code Access Security Basics.

Note

Code Access Security (CAS) has been deprecated across all versions of .NET Framework and .NET. Recent versions of .NET do not honor CAS annotations and produce errors if CAS-related APIs are used. Developers should seek alternative means of accomplishing security tasks.

See also

How to: Read a Value from a Registry Key - Visual Basic (2024)
Top Articles
Platform - Glossary | CSRC
Relationships by Marriage | Britannica Dictionary
Sprinter Tyrone's Unblocked Games
What spices do Germans cook with?
Wisconsin Women's Volleyball Team Leaked Pictures
Kraziithegreat
Nfr Daysheet
BULLETIN OF ANIMAL HEALTH AND PRODUCTION IN AFRICA
Riegler & Partner Holding GmbH auf LinkedIn: Wie schätzen Sie die Entwicklung der Wohnraumschaffung und Bauwirtschaft…
Chastity Brainwash
Shuiby aslam - ForeverMissed.com Online Memorials
Washington Poe en Tilly Bradshaw 1 - Brandoffer, M.W. Craven | 9789024594917 | Boeken | bol
Lonadine
Darksteel Plate Deepwoken
Swedestats
Boston Gang Map
Weepinbell Gen 3 Learnset
Hennens Chattanooga Dress Code
Bible Gateway passage: Revelation 3 - New Living Translation
Parc Soleil Drowning
Dtlr Duke St
Routing Number For Radiant Credit Union
Koninklijk Theater Tuschinski
Craigslist Wilkes Barre Pa Pets
4 Methods to Fix “Vortex Mods Cannot Be Deployed” Issue - MiniTool Partition Wizard
Radical Red Ability Pill
Cowboy Pozisyon
Leben in Japan – das muss man wissen - Lernen Sie Sprachen online bei italki
Downtown Dispensary Promo Code
Hwy 57 Nursery Michie Tn
Maths Open Ref
Mastering Serpentine Belt Replacement: A Step-by-Step Guide | The Motor Guy
Everything You Need to Know About Ñ in Spanish | FluentU Spanish Blog
Egg Crutch Glove Envelope
Fbsm Greenville Sc
The Menu Showtimes Near Amc Classic Pekin 14
Spy School Secrets - Canada's History
Baddies Only .Tv
Sports Clips Flowood Ms
Beaver Saddle Ark
Western Gold Gateway
Hingham Police Scanner Wicked Local
Heelyqutii
Mckinley rugzak - Mode accessoires kopen? Ruime keuze
A Comprehensive 360 Training Review (2021) — How Good Is It?
Brandon Spikes Career Earnings
888-822-3743
Cvs Coit And Alpha
Vci Classified Paducah
Haunted Mansion Showtimes Near Millstone 14
303-615-0055
Craigslist Cars And Trucks For Sale By Owner Indianapolis
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 6033

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.