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 !!!!!
Printable View
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 !!!!!
Use the Registry API to write your own functions for Saving Data anywhere within the Registry, ie.
Code: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
[email protected]
[email protected]
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.????