Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base

Post new topic   Reply to topic
Reading Registry Values (Local registry method)
View previous topic :: View next topic  
Author Message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Apr 15th, 2004 09:24 AM    Post subject: Reading Registry Values (Local registry method) Reply with quote

Reading registry values is easier if your pulling from your local registry only. Here is some code that will get the Windows ProductID from HKEY_LOCAL_MACHINE\Software\microsoft\windows\currentversion

Code:

Imports Microsoft.Win32
'  Start of Module/Form
Dim regKey As RegistryKey
Dim pathKey As String

pathKey = "Software\microsoft\windows\currentversion"
regKey = Registry.LocalMachine.OpenSubKey(pathKey, False)

Console.WriteLine(regKey.GetValue("ProductID"))


Notes:
--If you want to get a value from HKEY_CURRENT_USER or one of the other hives, you would need to change the Registry.LocalMachine line to read Registry.CurrentUser, or whatever hive your looking for.
--You can change the OpenSubKey to OpenSubKey(pathKey, True) if you wish to be able to write to the registry using SetValue instead of GetValue.

edit: Added the "Imports Microsoft.Win32". This is required for this to work.
_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
Philwn
Freshman


Joined: 25 Feb 2004
Posts: 40
Location: England

PostPosted: Nov 4th, 2004 05:18 AM    Post subject: ok Reply with quote

with andir's code it is sayin registrykey is not defined and theres a bunch of other mistakes
_________________
Nothing good to put here
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Nov 4th, 2004 09:05 AM    Post subject: Reply with quote

Did you include the line:

Imports Microsoft.Win32

before any other line? This should be at the top of your module/form before any other line. The Dim statements would then be in the function where your accessing the registry.
_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic