Hello everyone!
I know it’s been a while since my last post, been rather occupied with other stuff so didn’t really have time to post on my blog.
Anyhow, back to business.
Today I’m going to explain to you how to work with the Windows Registry in your VB.NET application.
This entry will be divided into 5 parts:
- Working with Windows Registry in VB.NET – Part 1: General information about the Registry
- Working with Windows Registry in VB.NET – Part 2: Writing to the Registry
- Working with Windows Registry in VB.NET – Part 3: Reading from the Registry
- Working with Windows Registry in VB.NET – Part 4: Deleting from the Registry
- Working with Windows Registry in VB.NET – Part 5: Everything in a nutshell
To some working with the registry might sound complicated but guess what, it’s not!
It’s so simple, that I don’t really get why they don’t address this in programming classes because working with the Windows Registry is really handy for storing application based settings without having to work with plain text files or whatever.
Let’s get started!
First of all, you’ll need to understand the basics of the Windows Registry and how it works.
You can browse the registry by pressing the windows key + r and typing “regedit”. This will open up the Register-editor.
In total, there are 5 hives: (For XP & Vista, older versions have additional hives available)
- HKEY_CLASSES_ROOT
- Used to store information regarding registerd applications.
- HKEY_CURRENT_USER
- Used to store settings that are specific to the currently logged-in user.
- HKEY_LOCAL_MACHINE
- Used to store settings that are specific to the local machine.
- HKEY_USERS
- Contains subkeys corresponding to the HKEY_CURRENT_USER for each user profile actively loaded.
- HKEY_CURRENT_CONFIG
- Used to store information gathered at runtime. Information stored in this key is not perma stored on disk
As a programmer, you’d be most interested in the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives because these are the most usefull to your application.
Most likely you’ll create an application that is user-based (in other words, every user on the computer can have different settings etc) or an application that is computer-based (The same settings apply for everyone on the machine)
So that’ll be HKEY_CURRENT_USER for user-based applications and HKEY_LOCAL_MACHINE for computer-based applications.
Once you’ve decided what hive is most suitable for you, we can get started with writing to and reading from the Registry.