| View previous topic :: View next topic |
| Author |
Message |
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Apr 15th, 2004 09:24 AM Post subject: Reading Registry Values (Local registry method) |
|
|
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 |
|
Philwn Freshman
Joined: 25 Feb 2004 Posts: 40 Location: England
|
Posted: Nov 4th, 2004 05:18 AM Post subject: ok |
|
|
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 |
|
Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Nov 4th, 2004 09:05 AM Post subject: |
|
|
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 |
|
|