How can I write and read from the registry?
Printable View
How can I write and read from the registry?
u can use GetSetting and SaveSetting
sample
VB Code:
'// Make a new project. Add a module. To the form add three text boxes and two command buttons. '// Code: '// Add this code To the module: Option Explicit Public Const ThisApp = "My Company" Public Const ThisKey = "My Prog Name" Global Name As String Global Phone As String Global PostCode As String '// Add this code To the first Command button:(Load) Private Sub Command1_Click() Dim Name, Phone, PostCode As String Name = GetSetting(ThisApp, ThisKey, "Name", "") Phone = GetSetting(ThisApp, ThisKey, "Phone", "") PostCode = GetSetting(ThisApp, ThisKey, "PostCode", "") Text1.Text = (Name) Text2.Text = (Phone) Text3.Text = (PostCode) End Sub '// Add this code To the Second Command button:(Save) Private Sub Command2_Click() Dim Name, Phone, PostCode As String SaveSetting ThisApp, ThisKey, "Name", Text1.Text SaveSetting ThisApp, ThisKey, "Phone", Text2.Text SaveSetting ThisApp, ThisKey, "PostCode", Text3.Text End Sub
note that if you want to be able to specify exactly where you want to put values in the registry and have more functionality with the registry you have to use the API registry funtions.
darre1 is right, this tutorial might help if u want to accomplish this : http://161.58.186.98/registry/registry2/
This works too.
Lots of people suggest useing API. I always suggest this
because its not alot of code.
Can anyone tell me whats better, this or API?
VB Code:
Private Sub Command1_Click() Dim WshShell As Object Set WshShell = CreateObject("wscript.Shell") WshShell.RegWrite "HKLM\software\dumbtest\Value", "Update", "REG_SZ" Debug.Print WshShell.RegRead("HKLM\software\dumbtest\Value") WshShell.RegDelete "HKLM\software\dumbtest\Value" 'deletes value WshShell.RegDelete "HKLM\software\dumbtest\Value\" 'deletes entire key Set WshShell = Nothing End Sub
That is all
Seahag