REGISTRY read write delete

Just starting out? Need help? Post your questions and find answers here.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Paul wrote:
PB wrote:> Here's your fishin' pole PB :lol:

Thanks Paul! :) Why do we have to "create" the key before deleting it?
I've never done that before, which is probably why I always failed...

Hi PB,

In this example we are using RegCreateKey as a quick way to open the subkey we want to work with (and delete) since RegCreateKey can be used to Open or Create a subkey.

Without first opening the subkey, RegDeleteValue will fail.


i was quicker mentioning the right api... i never get the credit, whehehehehehehehehehehe!
Sorry, didn't know it was a contest :wink:
I tried your above code.. and I noticed.. that if the programmer screws
up the SubKey.s .. that key is then created, and not deleted..
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1287
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

I tried your above code.. and I noticed.. that if the programmer screws
up the SubKey.s .. that key is then created, and not deleted..
Of course it creates a subkey, that is what it is told to do.
It's the programmers job not to screw up. No different than using your above code to accidentally delete your entire registry. :twisted:

hehe
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Paul wrote:
I tried your above code.. and I noticed.. that if the programmer screws
up the SubKey.s .. that key is then created, and not deleted..
Of course it creates a subkey, that is what it is told to do.
It's the programmers job not to screw up. No different than using your above code to accidentally delete your entire registry. :twisted:

hehe
There would be no accident.. as it can't delete something that is not
there..

But yours.. if not found.. will create it.. and *not* delete it... ;)


Noah Phense aka No Offense... I don't know about your post.. but none
of this code is mine.. <g>


- np

*edit*

I'm just learning what the codes should be.. Then of course customize it
to my liking..
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1287
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Don't see what the big probelm is...
Code snippets are simply a starting point to get you going.

There's the source,
You're the programmer,
Make it do what you want it to do.

Simply delete the subkey if you can't specify the proper subkey in the first place. :roll:
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Paul wrote:Don't see what the big probelm is...
Code snippets are simply a starting point to get you going.

There's the source,
You're the programmer,
Make it do what you want it to do.

Simply delete the subkey if you can't specify the proper subkey in the first place. :roll:
No problem.. (pondering post counts..) :idea:

Thanks Paul for all your help!

- np
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

NoahPhense wrote:

Code: Select all

Procedure Reg_DeleteKey(topKey, sKeyName.s, ComputerName.s) 
  
  If Left(sKeyName, 1) = "" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegDeleteKey_(topKey, @sKeyName) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegDeleteKey_(lhRemoteRegistry, @sKeyName) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    DeleteKey = #True 
  Else 
    DeleteKey = #False 
  EndIf 
  ProcedureReturn DeleteKey 
EndProcedure 
NoahPhense, I still don't get it. Where in your example does it allow the
deletion of a single entry? All I see is TopKey and KeyName, which do not
point to a single entry in the Registry. From what I can tell:

TopKey = #HKEY_CURRENT_USER
KeyName = Software\Microsoft\Windows\CurrentVersion\Run

So if I run your code, it'll delete everything in the "Run" area, instead of
just the single entry in there that I want deleted. See what I mean? Paul's
example works and it's very different to your example, so I'm wondering
how your example does it?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

PB wrote:
NoahPhense wrote:

Code: Select all

Procedure Reg_DeleteKey(topKey, sKeyName.s, ComputerName.s) 
  
  If Left(sKeyName, 1) = "" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegDeleteKey_(topKey, @sKeyName) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegDeleteKey_(lhRemoteRegistry, @sKeyName) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    DeleteKey = #True 
  Else 
    DeleteKey = #False 
  EndIf 
  ProcedureReturn DeleteKey 
EndProcedure 
NoahPhense, I still don't get it. Where in your example does it allow the
deletion of a single entry? All I see is TopKey and KeyName, which do not
point to a single entry in the Registry. From what I can tell:

TopKey = #HKEY_CURRENT_USER
KeyName = Software\Microsoft\Windows\CurrentVersion\Run

So if I run your code, it'll delete everything in the "Run" area, instead of
just the single entry in there that I want deleted. See what I mean? Paul's
example works and it's very different to your example, so I'm wondering
how your example does it?

Code: Select all


; this will delete the entire rruunn key from the reg ..
Debug Reg_DeleteKey(#hkey_current_user, "software\microsoft\windows\currentversion\rruunn", "w2kpro")

; this will delete rruunn key and all subkeys from the reg ..
Debug Reg_DeleteKeyWithAllSub(#hkey_current_user, "software\microsoft\windows\currentversion\rruunn", "w2kpro")

; keep in mind that values are not keys, keys are only in the form of a "registry folder" ..
Let me know if you have other questions..

- np
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

So if you "really" wanted to clear out the Run section.. you could
completely remove the Run section.. then recreate it..

Right now, I'm working on something like this.. so I can evaluate
and select what to remove.. etc..

Code: Select all

;info: Read and change the Registry / FileAssociate 
Procedure Reg_SetValue(topKey, sKeyName.s, sValueName.s, vValue.s, lType, ComputerName.s) 
  lpData.s 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    lpcbData = 255 
    lpData = Space(255) 
    
    Select lType 
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1) 
      Case #REG_DWORD 
        lValue = Val(vValue) 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4) 
    EndSelect 
    
    RegCloseKey_(hKey) 
    ergebnis = 1 
    ProcedureReturn ergebnis 
  Else 
    MessageRequester("Fehler", "Ein Fehler ist aufgetreten", 0) 
    RegCloseKey_(hKey) 
    ergebnis = 0 
    ProcedureReturn ergebnis 
  EndIf 
EndProcedure


Procedure.s Reg_GetValue(topKey, sKeyName.s, sValueName.s, ComputerName.s) 
  lpData.s 
  GetValue.s ="" 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    lpcbData = 255 
    lpData = Space(255) 
    
    GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData) 
    
    If GetHandle = #ERROR_SUCCESS 
      Select lType 
        Case #REG_SZ 
          GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData) 
          
          If GetHandle = 0 
            GetValue = Left(lpData, lpcbData - 1) 
          Else 
            GetValue = "" 
          EndIf 
          
        Case #REG_DWORD 
          GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, @lpDataDWORD, @lpcbData) 
          
          If GetHandle = 0 
            GetValue = Str(lpDataDWORD) 
          Else 
            GetValue = "0" 
          EndIf 
          
      EndSelect 
    EndIf 
  EndIf 
  RegCloseKey_(hKey) 
  ProcedureReturn GetValue 
EndProcedure 
Procedure.s Reg_ListSubKey(topKey, sKeyName.s, Index, ComputerName.s) 
  lpName.s 
  lpftLastWriteTime.FILETIME 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    lpcbName = 255 
    lpName = Space(255) 
    
    GetHandle = RegEnumKeyEx_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, @lpftLastWriteTime) 
    
    If GetHandle = #ERROR_SUCCESS 
      ListSubKey.s = Left(lpName, lpcbName) 
    Else 
      ListSubKey.s = "" 
    EndIf 
  EndIf 
  RegCloseKey_(hKey) 
  ProcedureReturn ListSubKey 
EndProcedure 
Procedure Reg_DeleteValue(topKey, sKeyName.s, sValueName.s, ComputerName.s) 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    GetHandle = RegDeleteValue_(hKey, @sValueName) 
    If GetHandle = #ERROR_SUCCESS 
      DeleteValue = #True 
    Else 
      DeleteValue = #False 
    EndIf 
  EndIf 
  RegCloseKey_(hKey) 
  ProcedureReturn DeleteValue 
EndProcedure 
Procedure Reg_CreateKey(topKey, sKeyName.s, ComputerName.s) 
  lpSecurityAttributes.SECURITY_ATTRIBUTES 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegCreateKeyEx_(topKey, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegCreateKeyEx_(lhRemoteRegistry, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    GetHandle = RegCloseKey_(hNewKey) 
    CreateKey = #True 
  Else 
    CreateKey = #False 
  EndIf 
  ProcedureReturn CreateKey 
EndProcedure 
Procedure Reg_DeleteKey(topKey, sKeyName.s, ComputerName.s) 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegDeleteKey_(topKey, @sKeyName) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegDeleteKey_(lhRemoteRegistry, @sKeyName) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    DeleteKey = #True 
  Else 
    DeleteKey = #False 
  EndIf 
  ProcedureReturn DeleteKey 
EndProcedure 
Procedure.s Reg_ListSubValue(topKey, sKeyName.s, Index, ComputerName.s) 
  lpName.s 
  lpftLastWriteTime.FILETIME 
  ListSubValue.s 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  
  If GetHandle = #ERROR_SUCCESS 
    lpcbName = 255 
    lpName = Space(255) 
    
    GetHandle = RegEnumValue_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, 0) 
    
    If GetHandle = #ERROR_SUCCESS 
      ListSubValue = Left(lpName, lpcbName) 
    Else 
      ListSubValue = "" 
    EndIf 
    RegCloseKey_(hKey) 
  EndIf 
  ProcedureReturn ListSubValue 
EndProcedure 
Procedure.b Reg_KeyExists(topKey, sKeyName.s, ComputerName.s) 
  
  If Left(sKeyName, 1) = "\" 
    sKeyName = Right(sKeyName, Len(sKeyName) - 1) 
  EndIf 
  
  If ComputerName = "" 
    GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    KeyExists = #True 
  Else 
    KeyExists = #False 
  EndIf 
  ProcedureReturn KeyExists 
EndProcedure 
Procedure Reg_DeleteKeyWithAllSub(topKey,sKeyName.s,ComputerName.s) 
  i=0 
  a$="" 
  Repeat 
    b$=a$ 
    a$=Reg_ListSubKey(topKey,sKeyName,0,"") 
    If a$<>"" 
      Reg_DeleteKeyWithAllSub(topKey,sKeyName+"\"+a$,"") 
    EndIf 
  Until a$=b$ 
  Reg_DeleteKey(topKey, sKeyName, ComputerName) 
EndProcedure 
Procedure Reg_CreateKeyValue(topKey,sKeyName.s,sValueName.s,vValue.s,lType,ComputerName.s) 
  Reg_CreateKey(topKey,sKeyName,ComputerName) 
  ProcedureReturn Reg_SetValue(topKey,sKeyName,sValueName,vValue,lType,ComputerName) 
EndProcedure 

Procedure AssociateFileEx(ext$,ext_description$,programm$,icon$,prgkey$,cmd_description$,cmd_key$) 
  cmd$=Chr(34)+programm$+Chr(34)+" "+Chr(34)+"%1"+Chr(34) 
  If GetVersion_() & $FF0000 ; Windows NT/XP 
    Reg_CreateKeyValue(#HKEY_CLASSES_ROOT, "Applications\"+prgkey$+"\shell\"+cmd_description$+"\command","",cmd$,#REG_SZ,"") 
    If ext_description$ 
      Key$=ext$+"_auto_file" 
      Reg_CreateKeyValue(#HKEY_CLASSES_ROOT  ,"."+ext$           ,"",Key$            ,#REG_SZ,"") 
      Reg_CreateKeyValue(#HKEY_CLASSES_ROOT  ,Key$               ,"",ext_description$,#REG_SZ,"") 
      If icon$ 
        Reg_CreateKeyValue(#HKEY_CLASSES_ROOT,Key$+"\DefaultIcon","",icon$           ,#REG_SZ,"") 
      EndIf 
    EndIf 
    Reg_CreateKeyValue(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"Application",prgkey$,#REG_SZ,"") 
  Else ;Windows 9x 
    Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE  ,"Software\Classes\."+ext$                     ,"",prgkey$         ,#REG_SZ,"") 
    If ext_description$ 
      Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$                   ,"",ext_description$,#REG_SZ,"") 
    EndIf 
    If icon$ 
      Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\DefaultIcon"    ,"",icon$           ,#REG_SZ,"") 
    EndIf 
    If cmd_description$<>cmd_key$ 
      Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$,"",cmd_description$,#REG_SZ,"") 
    EndIf 
    Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE  ,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$+"\command","",cmd$,#REG_SZ,"") 
  EndIf 
EndProcedure 
Procedure Remove_AssociateFile(ext$,prgkey$) 
  If GetVersion_() & $FF0000 ; Windows NT/XP 
    Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,"Applications\"+prgkey$,"") 
    Key$=ext$+"_auto_file" 
    Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,"."+ext$,"") 
    Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,Key$,"") 
    Reg_DeleteKeyWithAllSub(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"") 
  Else ;Windows 9x 
    Reg_DeleteKeyWithAllSub(#HKEY_LOCAL_MACHINE  ,"Software\Classes\."+ext$,"") 
    Reg_DeleteKeyWithAllSub(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$,"") 
  EndIf 
EndProcedure 
Procedure AssociateFile(ext$,ext_description$,programm$,icon$) 
  AssociateFileEx(ext$,ext_description$,programm$,icon$,GetFilePart(programm$),"open","open") 
EndProcedure 



; THE START OF MY CRAP

;test.s = Reg_GetValue(#HKEY_LOCAL_MACHINE, "software\3com\TCAUDIAG", "version", "w2kpro") 
;Debug Reg_KeyExists(#HKEY_LOCAL_MACHINE, "software\3com\tcaudiag", "w2kpro") 
;Debug test
; Reg_SetValue(topKey, sKeyName.s, sValueName.s, vValue.s, lType, ComputerName.s) 
; Debug Reg_SetValue(#HKEY_LOCAL_MACHINE, "software\activepdf\settings", "defaultdir", "test", #REG_SZ, "w2kpro")
;a.s = Reg_ListSubKey(#HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentversion\run", 0, "w2kpro") 
;b.s = Reg_ListSubKey(#HKEY_LOCAL_MACHINE, "software\microsoft\windows\currentversion\run", 1, "w2kpro") 
NewList RunList.s()

Global strLocation.s
Global strDivider.s
Global strKeyLocal.s
Global strKeyCurrent.s
Global strComp.s

strLocation.s   = "software\microsoft\windows\currentversion\run"
strDivider.s    = "[***]"
strKeyLocal.s   = "hkey_local_machine"
strKeyCurrent.s = "hkey_current_user"
strComp.s       = "w2kpro"

Procedure cat1()
 
  ResetList(RunList())
  
  For x = 0 To 74
    a.s = Reg_ListSubValue(#hkey_local_machine, strLocation, x, strComp)
    b.s = Reg_GetValue(#hkey_local_machine, strLocation, a, strComp)
    
    If Len(Trim(a)) < 1
      ; do nothing
    Else
      AddElement(RunList())
      RunList() = Str(x) + strDivider + strKeyLocal + strDivider + strLocation +strDivider + a + strDivider + b
    EndIf
  Next x
EndProcedure

Procedure cat2()
  rr = CountList(RunList())
  rr + 1

  For x = 0 To 74
    a.s = Reg_ListSubValue(#hkey_current_user, strLocation, x, strComp)
    b.s = Reg_GetValue(#hkey_current_user, strLocation, a, strComp)
    
    If Len(Trim(a)) < 1
      ; do nothing
    Else
      AddElement(RunList())
      RunList() = Str(rr) + strDivider + strKeyCurrent + strDivider + strLocation + strDivider + a + strDivider + b
      rr+1
    EndIf
  Next x
EndProcedure


Procedure dog1()
  ResetList(RunList())
  While NextElement(RunList())
    Debug RunList() ; Display all the list elements
  Wend
EndProcedure



cat1()
cat2()
dog1()



End
I'm simply using the code that was posted to this thread early on.. and
testing it to see what I can do "safely" ..

- np
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

another attempt :-)

Code: Select all

Procedure.l x_regdelete(topkey.l,subkey.s,name.s)          ; delete name and / or subkey from registry
  Protected handle.l
  ;
  ; *** delete a subkey or a named value
  ;
  ; in:   topkey.l
  ;       subkey.s
  ;       name.s      - leave empty to delete the whole subkey, fill in to delete a single named value
  ; out:  0           - succeeded
  ;       <>0         - error
  ;
  If name = ""              ; delete a complete subkey including all named values
    handle = 0
    RegOpenkeyEx_(topkey,0,0,#KEY_ALL_ACCESS,@handle)
    If handle <> 0
      Debug "!"
      x_retval = RegDeleteKey_(handle,@subkey)
      RegCloseKey_(handle)
    EndIf
  Else                      ; delete a named value from a subkey
    handle = 0
    RegOpenkeyEx_(topkey,@subkey,0,#KEY_ALL_ACCESS,@handle)
    If handle <> 0
      x_retval = RegDeleteValue_(handle,@name)
      RegCloseKey_(handle)
    EndIf
  EndIf
  ;
  If handle = 0            ; couldn't open the key so indicate an error (x_retval <> 0)
    x_retval = -1
  EndIf
  ;
  ; don't need it now, but it may come in handy one day, here's how to delete a whole bunch of values
  ; from a subkey, but not the subkey itself
  ;
  ;   handle.l = 0
  ;   RegOpenkeyEx_(topkey,@subkey,0,#KEY_ALL_ACCESS,@handle)
  ;   If handle <> 0
  ;     buffer_max = 0
  ;     RegQueryInfoKey_(topkey,0,0,0,0,0,0,0,@buffer_max,0,0,0)
  ;     buffer_max = buffer_max+1
  ;     ;
  ;     buffer_l = buffer_max
  ;     Buffer = Space(buffer_l)
  ;     While RegEnumValue_(handle,0,@Buffer,@buffer_l,0,0,0,0) = 0
  ;      RegDeleteValue_(handle,@Buffer)
  ;      Debug Buffer
  ;      buffer_l = buffer_max
  ;       Buffer = Space(buffer_l)
  ;     Wend
  ;     RegCloseKey_(handle)
  ;   EndIf
  ; 
  ProcedureReturn x_retval
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply