Read/Write String to Registry.

Just starting out? Need help? Post your questions and find answers here.
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Read/Write String to Registry.

Post by +18 »

Read/Write String to Registry.
there is a good code by BigJack for Read/Write DWORD to Registry:

Code: Select all

;-========= Write DWORD to Registry ============ 
Procedure RegWriteDword(HKMain,HKSub$,HKEntry$,HKValue.l)

If RegCreateKeyEx_(HKMain, HKSub$, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo)= #ERROR_SUCCESS 
  RegSetValueEx_(NewKey, HKEntry$, 0, #REG_DWORD, @HKValue,4) 
  RegCloseKey_(NewKey) 
EndIf 
EndProcedure 


;-======== Read DWORD from Registry ======= 
Procedure RegReadDWord(section,path$,key$) 
  value=-1 : datasize.l=4 ; 4 bytes = 32 bits (long). 
  If RegOpenKeyEx_(section,path$,0,#KEY_READ,@tmp)=#ERROR_SUCCESS 
    If RegQueryValueEx_(tmp,key$,0,0,@value,@datasize)<>#ERROR_SUCCESS : value=-1 : EndIf 
    RegCloseKey_(tmp) 
  EndIf 
  ProcedureReturn value 
EndProcedure 
;========== Testing ===================== 
;------ Write Dword Value -------- 
ValueWrite.l = 1234 
RegWriteDword(#HKEY_CURRENT_USER,"Software\DTM\Test","TestEntry",ValueWrite) 

;----- Read DWORD value ----- 
ValueRead.l = RegReadDWord(#HKEY_CURRENT_USER,"Software\DTM\Test","TestEntry") 
Debug ValueRead
I change this to String for Writing ,but i can't for read string.
I test on XP SP3 and PB 4.20,Result was good for Writing only.
Please help me
or if have a better function ,please share those.

Code: Select all

;-========= Write String to Registry ============ Converted
Procedure RegWriteString(HKMain,HKSub$,HKEntry$,HKValue.s)

If RegCreateKeyEx_(HKMain, HKSub$, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo)= #ERROR_SUCCESS 
  RegSetValueEx_(NewKey, HKEntry$, 0, #REG_SZ, @HKValue,256) 
  RegCloseKey_(NewKey) 
EndIf 
EndProcedure 
;-========= Write String to Registry ============non
;????????????????????????


;========== Testing ===================== 
;------ Write String Value -------- 
ValueWrite$ = "srod Sparkie FluidByte"
RegWriteString(#HKEY_CURRENT_USER,"Software\app1\Data1","Data0000",ValueWrite$) 
;------ Read String Value --------
;????????????????????????
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Code: Select all

;------ Read String Value -------- 
;???????????????????????? 
Procedure.s RegReadString(HKMain, HKSub$, HKEntry$) 
  hKey = 0
  If RegOpenKeyEx_(#HKEY_CURRENT_USER, HKSub$, 0, #KEY_QUERY_VALUE, @hKey) = #ERROR_SUCCESS 
    result$ = Space(260)
    bufLen = Len(result$)
    If hKey 
      If RegQueryValueEx_(hKey, HKEntry$, 0, 0, @result$, @bufLen) <> #ERROR_SUCCESS
        result$ = "Error reading Registry"
      EndIf
      RegCloseKey_(hKey) 
    EndIf 
  Else
    result$ = "Error opening Registry key"
  EndIf 
ProcedureReturn result$ 
EndProcedure 
Debug RegReadString(#HKEY_CURRENT_USER,"Software\app1\Data1","Data0000") 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

Thanks Sparkie
You're unique like god
Post Reply