Hello i need code how to read from registry.
so for example i got HKEY_LOCAL_MACHINE\software\myapp\important\name
So i need to read the value of "name" and write it on label
ty
Printable View
Hello i need code how to read from registry.
so for example i got HKEY_LOCAL_MACHINE\software\myapp\important\name
So i need to read the value of "name" and write it on label
ty
Hai Lulzorlot,
I normally use API methods for reading form the registry.
the api's are
RegOpenKeyEx() - First you need to open that key HKEY_LOCAL_MACHINE\software\myapp\important\name
RegQueryValueEx() - This api return that value you wanted.
If you search the code bank of VBF, you have many examples there.
Also, there are few vbnative function also to read and write to the reg. but i am not much with them :)
Those vbnative functions only read/write to the VB and VBA Programs Settings hive.
GetSetting/SaveSetting
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
Yah rob,
tx for remembering that.
Hello i fuond this module.
But how can i use it.I mean how can i read from registry
i need to read value of HKEY_LOCAL_MACHINE\software\myapp\important\name
ty
Attached is the class I wrote to deal with the registry. It would handle what you ask like this:Code:Public Sub Sample()
Dim reg As clsRegistry
Dim strName As String
Set reg = New clsRegistry
strName = reg.ReadString("Software\MyApp\Important", "Name", "", rrLocalMachine)
Set reg = Nothing
MsgBox strName
End Sub
this is my piece of code which I had used in my application and it is working fine...
vb Code:
Private Function RegKeyRead(strPath As String) As String Dim objCreate As Object Set objCreate = CreateObject("wscript.shell") RegKeyRead = objCreate.RegRead(strPath) End Function
vb Code:
Private Sub RegKeyWrite(strRegPath As String, strRegNewVal As String) Dim objCreate As Object Set objCreate = CreateObject("wscript.shell") objCreate.RegWrite strRegPath, strRegNewVal, "REG_SZ" End Sub
Please note that if you give strRegPath as a new value which is not in Regedit, it will create the same and mainly this is for "REG_SZ".
Thanks guys it works
How do you specify the hive? Note that the OP is trying to read from LOCAL_MACHINE, not CURRENT_USER.Quote:
Originally Posted by sivagk
Probably have to pass the entire path in the strPath argument.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Outlook
or such I would assume from the look of it.
Ah, makes sense.