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
Robert Moses Playground Highlights : NYC Parks
U.S. mobile messengers MAU 2019 | Statista
Foxy Roxxie Coomer
Dairy Queen Lobby Hours
Lakers Game Summary
Asist Liberty
Cars & Trucks - By Owner near Kissimmee, FL - craigslist
Poe Pohx Profile
Athletic Squad With Poles Crossword
Ou Class Nav
1TamilMV.prof: Exploring the latest in Tamil entertainment - Ninewall
Myunlb
Craigslist Heavy Equipment Knoxville Tennessee
Costco Gas Foster City
How to find cash from balance sheet?
Https://Store-Kronos.kohls.com/Wfc
Apply for a credit card
Uta Kinesiology Advising
Dallas Craigslist Org Dallas
Schedule An Oil Change At Walmart
Imouto Wa Gal Kawaii - Episode 2
480-467-2273
Synergy Grand Rapids Public Schools
Dove Cremation Services Topeka Ks
Churchill Downs Racing Entries
Star Wars Armada Wikia
Stickley Furniture
Myaci Benefits Albertsons
Free Tiktok Likes Compara Smm
Craigslist Middletown Ohio
Advance Auto Parts Stock Price | AAP Stock Quote, News, and History | Markets Insider
6465319333
How to Destroy Rule 34
Wsbtv Fish And Game Report
SF bay area cars & trucks "chevrolet 50" - craigslist
Vivek Flowers Chantilly
The Best Restaurants in Dublin - The MICHELIN Guide
Newsweek Wordle
All Characters in Omega Strikers
Traumasoft Butler
Nina Flowers
CrossFit 101
Human Resources / Payroll Information
Advance Auto.parts Near Me
Walmart Front Door Wreaths
Costner-Maloy Funeral Home Obituaries
Image Mate Orange County
Twizzlers Strawberry - 6 x 70 gram | bol
Obituary Roger Schaefer Update 2020
Volstate Portal
Cbs Scores Mlb
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.