Link to home
Start Free TrialLog in
Avatar of AlexPonnath
AlexPonnathFlag for United States of America

asked on

How can i read and write to registry from VB.net

I am looking for some code which does the folowing

a) read a specified registry key
b) write a value to a specific key
c) check if a key exists
d) create a new key

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlexPonnath

ASKER

Ok something is missing here..

i am using the code from the link provided, except i placed it in a module when i try to compile i get an error for
C:\Documents and Settings\Administrator.ICCINET\My Documents\Visual Studio Projects\LIBD\customeLookup.vb(62): 'LocalMachine' is not a member of 'LIBD.registry'.

any idea what i am missing ?

Imports Microsoft.Win32

Module registry
    Public Function createKey()
        Dim regKey As RegistryKey
        regKey = registry.LocalMachine.OpenSubKey("SOFTWARE", True)
        regKey.CreateSubKey("MyApp")
        regKey.Close()
        MsgBox("Registry key HKLM\Software\MyApp created.")
End Function
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you have the rights to access the registry ?
Does you subKey exist ?
That seems overly complicated, here is how I do it:

SaveSetting("APPLICATION_NAME", "FOLDER_NAME", "File_Name", "VALUE_YOU_WANT_STORED")

GetSetting("APPLICATION_NAME, "FOLDER_NAME", "File_Name", "")

DeleteSetting(APPLICATION_NAME, "FOLDER_NAME")

These values will be stored in the registry under "My Computer\HKEY_CURRENT_USER\Software\VB and VBA Program Settings"
Avatar of S-Twilley
S-Twilley

Well the code samples given have been to access anywhere in the registry... hence the "complication"
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial