Using RegSetValueEx to Write Information to the Registry
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 Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Sub cmdWrite_Click() Dim strValue As String Dim strKeyName As String Dim lngRetval As Long Dim lngLength As Long Dim lngKey As Long strKeyName = "KeyName" & vbNullString If RegOpenKeyEx(HKEY_CURRENT_USER, strKeyName, 0, KEY_WRITE, lngKey) Then End If strValue = "YourValue" & vbNullString lngLength = Len("YourValue") + 1 lngRetval = RegSetValueEx( lngKey, "YourValue", 0, REG_SZ, ByVal strValue, lngLength) 'Close the key RegCloseKey (lngKey) End Sub
1. | Working with the Registry Using the VBA Registry Functions | ||
2. | Reads a value from the Windows Registry | ||
3. | Write a value from the Windows Registry | ||
4. | Using RegQueryValueEx to Read Registry Information |