Hello all:
Here's the situation:
I found these Firefly functions but I don't quite understand how to use them...:
FF_SetRegistryString (ByVal_hLocation_As_Dword, ByVal_sSubKeys_As_String, ByVal_sValueName_As_String, ByVal_sData_As_String)_As_Long
FF_GetRegistryString (ByVal_hLocation_As_Dword, ByVal_sSubKeys_As_String, ByVal_sValueName_As_String, ByVal_sDefault_As_String)_As_String
I want to be able to read the value in HKEY_CURRENT_USER > CONTROL PANEL > DESKTOP > FOREGROUNDLOCKTIMEOUT
Then if the value is "00000", I want to change it to another value.
Can someone show me the actual way I would read this value and write a new value of "30d40"
Thanks
Patrick
Be aware that some, including the requested, registry value might not be of the "string" type (%REG_SZ). This is important when writing to the key, as otherwhise the type of value will be changed, and possibly rendered useless for other programs/functions. Here is an example of how to read the value (as a string, not as HEX/DWORD as it really is) with the FireFly function:
Dim RetVal As String
RetVal = FF_GetRegistryString (%HKEY_CURRENT_USER, "\Control Panel\Desktop", "ForegroundLockTimeout", "No value found")
And here is a, not so universal (only writes one type of key as it is now), function using API to write a HEX value back to the key:
'------------------------------------------------------------------------------
' SAVE a DWORD VALUE to the registry, returns nonzero if successful
'------------------------------------------------------------------------------
Function SetReg(ByVal hLocation As Dword, ByVal sSubKeys As String, ByVal sValueName As String, ByVal sData As String) As Long
Local hKey As Dword, zRegName As Asciiz * 1024, zRegVal As Asciiz * 1024, dwType As Dword, dwSize As Dword
zRegVal = sData
zRegName = sValueName
If hLocation = 0 Then hLocation = %HKEY_CURRENT_USER
If RegCreateKeyEx(hLocation, Trim$(sSubKeys, "\"), 0, "", 0, %KEY_WRITE, ByVal %Null, hKey, ByVal %Null) = %ERROR_SUCCESS Then
dwSize = SizeOf(zRegVal)
dwType = %REG_DWORD '# Or other type, like fx. %REG_SZ #
If RegSetValueEx(hKey, zRegName, 0, dwType, zRegVal, dwSize) = %ERROR_SUCCESS Then Function = %True
RegCloseKey hKey
End If
End Function
Thank you very much!
Patrick
Hi, I tried the following code inside a command button and a null value is returned (not a number in a string). The msgbox returns a blank string.:
Dim RetVal As String
RetVal = FF_GetRegistryString (%HKEY_CURRENT_USER, "\Control Panel\Desktop", "ForegroundLockTimeout", "No value found")
MsgBox RetVal,,"What was found:"
Any ideas?
Patrick
According to the "default value" I saw in the ForeGroundLockTimeout key, it's a HEX 0 (REG_DWORD). That's not gonna make much of a visual impression as a string in a MsgBox..
If I'm not mistaken, I don't think the FF function will do for this type of key value, only "regular strings". You should maybe look into the source code forum at PB. For example on this collection of functions ( http://www.powerbasic.com/support/forums/Forum7/HTML/002464.html ) donated of Balthasar Indermuehle.
Maybe at some point we'll get a wrapper for FF to read and write any registry value.