Sub RegSetValue(H_KEY&, RSubKey$, ValueName$, RegValue$)
'H_KEY must be one of the Key Constants
Dim lRtn& 'returned by registry functions, should be 0&
Dim hKey& 'return handle to opened key
Dim lpDisp&
Dim Sec_Att As SECURITY_ATTRIBUTES
Sec_Att.nLength = 12&
Sec_Att.lpSecurityDescriptor = 0&
Sec_Att.bInheritHandle = False
lRtn = RegCreateKeyEx(H_KEY, RSubKey, 0&, "", 0&, Key_Write, Sec_Att, hKey, lpDisp)
If lRtn <> 0 Then
Exit Sub 'No key open, so leave
End If
lRtn = RegSetValueEx(hKey, ValueName, 0&, REG_SZ, _
ByVal RegValue, CLng(Len(RegValue) + 1))
lRtn = RegCloseKey(hKey)
End Sub