PDA

Click to See Complete Forum and Search --> : Registery API


ADM1AVD
Jan 14th, 2000, 04:12 AM
When I use the SaveSettings function my string gets registered under the HKEY_LOCAL_USERS path. However I want to save the string in the HKEY_LOCAL_MACHINE\SOFTWARE path
HELP !!!!!

Aaron Young
Jan 14th, 2000, 04:27 AM
Use the Registry API to write your own functions for Saving Data anywhere within the Registry, ie.

Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData 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 Const HKEY_LOCAL_MACHINE = &H80000002

Private Sub Command1_Click()
Call SaveRegSetting("Software\Aaron Young", "MyValue", "Anything")
Caption = GetRegSetting("Software\Aaron Young", "MyValue")
End Sub

Private Sub SaveRegSetting(ByVal sSubKey As String, ByVal sValue As String, ByVal sData As String)
Dim lRegKey As Long

If RegCreateKey(HKEY_LOCAL_MACHINE, sSubKey, lRegKey) = 0 Then
Call RegSetValueEx(lRegKey, sValue, 0&, 1, ByVal sData, Len(sData))
Call RegCloseKey(lRegKey)
End If
End Sub

Private Function GetRegSetting(ByVal sSubKey As String, ByVal sValue As String) As String
Dim lRegKey As Long
Dim sData As String

If RegOpenKey(HKEY_LOCAL_MACHINE, sSubKey, lRegKey) = 0 Then
sData = Space$(255)
Call RegQueryValueEx(lRegKey, sValue, 0&, 1, ByVal sData, 255)
If InStr(sData, Chr(0)) Then
sData = Left$(sData, InStr(sData, Chr(0)) - 1)
End If
GetRegSetting = sData
Call RegCloseKey(lRegKey)
End If
End Function



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

ADM1AVD
Jan 14th, 2000, 05:22 AM
THANKS !!!!!
OK...What about if I need to get a string from a table in a database. I also need to put the code in a module not a form.????