|
-
Oct 2nd, 2002, 04:03 PM
#1
Thread Starter
Hyperactive Member
Reading a registry key from the windows registry
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...
-
Oct 2nd, 2002, 04:05 PM
#2
PowerPoster
Well
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
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 2nd, 2002, 04:19 PM
#3
-
Oct 2nd, 2002, 04:21 PM
#4
PowerPoster
Well
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"
Thats why I gave him both options...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 2nd, 2002, 04:22 PM
#5
-
Oct 2nd, 2002, 04:24 PM
#6
PowerPoster
Well
Originally posted by Mc Brain
I know!! I was explaining him the difference between the two approachs.
Applause...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 2nd, 2002, 04:26 PM
#7
Need-a-life Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|