How do I go about reading the info held in a registry key using VB and input it into a text box?
Thanks,
- Gabe
What are the dangerous of this? If any...
Printable View
How do I go about reading the info held in a registry key using VB and input it into a text box?
Thanks,
- Gabe
What are the dangerous of this? If any...
There is this from MSDN :
GetSetting
Returns a key setting value from an application's entry in the Windowsregistry.
Syntax
GetSetting(appname, section, key[, default])
The GetSetting function syntax has thesenamed arguments:
Part Description
appname Required.String expression containing the name of the application or project whose key setting is requested.
section Required. String expression containing the name of the section where the key setting is found.
key Required. String expression containing the name of the key setting to return.
default Optional.Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").
Remarks
If any of the items named in the GetSetting arguments do not exist, GetSetting returns the value of default.
And then there's Hack's take on it :
VB Code:
Private Const HKEY_CURRENT_USER = &H80000001 Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Sub Command1_Click() Dim Result As Long Dim KeyRet As Long Dim KeyToRead As String Dim KeyValue As String Dim Length As Long Result = RegOpenKey(HKEY_CURRENT_USER, "Software\New stuff\", KeyRet) KeyToRead = "demo" Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, "", Length) KeyValue = Space$(Length - 1) Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, ByVal KeyValue, Length) MsgBox KeyValue RegCloseKey KeyRet End Sub
Those are two ways of doing almost the same. SaveSetting and GetSetting won't let you use a personal path, but it will always use the "HKCU\Software\VB and VBA Program Settings"
Thats why I gave him both options...;)Quote:
Originally posted by Mc Brain
Those are two ways of doing almost the same. SaveSetting and GetSetting won't let you use a personal path, but it will always use the "HKCU\Software\VB and VBA Program Settings"
I know!! I was explaining him the difference between the two approachs.
Applause... :DQuote:
Originally posted by Mc Brain
I know!! I was explaining him the difference between the two approachs.
Thank you, thank you.... but I'm too humble to say that I deserve them ;)Quote:
Originally posted by James Stanich
Applause... :D