REGISTRY read write delete

Just starting out? Need help? Post your questions and find answers here.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

no lib, but it deletes a single key, not a whole stack of 'm though... gotta' do somethign yourself :-)

Code: Select all

; purebasic survival guide - pb3.90 sp1
; registry 1 - 10.11.2003 ejn (blueznl)
; http://www.xs4all.nl/~bluez/datatalk/pure1.htm
;
; - read from and write to registry
; - see the win32.hlp file for other variations
;
;
; *** create a new key
;
topkey.l = #HKEY_CURRENT_USER
subkey.s = "Control Panel\Desktop2"
handle.l = 0
result.l = 0
If RegCreateKeyEx_(topkey,@subkey,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS,0,@handle,@result)=0
  Debug "creation okay"
  RegCloseKey_(handle)
EndIf
;
; *** delete a key
;
If RegDeleteKey_(topkey,@subkey)=0
  Debug "deletion okay"
Else
  Debug "error deleting"
EndIf
;
; *** open key
;
topkey.l = #HKEY_CURRENT_USER
subkey.s = "Control Panel\Desktop"
handle.l = 0
If RegOpenkeyEx_(topkey,@subkey,0,#KEY_ALL_ACCESS,@handle)=0
  ;
  ; *** set or create a value
  ;
  name.s = "TileWallPaper"
  Buffer.s = "1"
  buffer_l.l = Len(Buffer)
  RegSetValueEx_(handle,@name,0,#REG_SZ,Buffer,buffer_l)
  ;
  Debug "value set"
  Debug Buffer
  ;
  ; *** read a value
  ;
  buffer_l.l = 255                                                    ; length of buffer
  Buffer.s = Space(valuebuffer_l)                                     ; buffer for returned data
  type.l = 0                                                          ; type of data in buffer
  If RegQueryValueEx_(handle,@name,0,@type,@Buffer,@buffer_l)=0      
    ;
    ; data found, could be different things, see win32.hlp for all possibilities
    ;
    Select type
      Case #REG_DWORD
        Value.l = PeekL(@Buffer)
      Case #REG_SZ
        Value.l = Val(Left(Buffer,buffer_l))
    EndSelect
    ;
    Debug "value read"
    Debug Value
  EndIf
  ;
  ; *** free handle
  ;
  RegCloseKey_(handle)
EndIf
;

( 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... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Hi Blueznl... I looked at your code but I fail to see how it deletes a single key.
Maybe "key" is the wrong term that I'm using? I want to delete a single item.
Your code seems to want to delete a "folder" of subkeys.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

oh i see, i think you are looking for RegDeleteValue_()
( 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... )
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

PB wrote:A lib is nice but it's like that old saying about giving a man a fish as opposed
to teaching him how to fish. ;) Still, I'll download the lib until I can learn how
to do it myself. Thanks!
Yeah, I actually have the regini lib installed. But when I go production,
on an application. I never use libs, only libs that I have compiled.
Because then I will always have the source. That's what started my reg
source search..

And the code that sverson posted, is perfect for me to learn from as it
uses all the proper API.

From that, I'll make my own lib. ;)

- np
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1287
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

PB wrote:A lib is nice but it's like that old saying about giving a man a fish as opposed
to teaching him how to fish. ;) Still, I'll download the lib until I can learn how
to do it myself. Thanks!

Here's your fishin' pole PB :lol:

Code: Select all

ProcedureDLL.l DeleteRegKey(OpenKey.l,SubKey.s,ValueName.s)
  hKey=0
  lResult=0 
  If RegCreateKey_(OpenKey,SubKey,@hKey)=0 
    If RegDeleteValue_(hKey,ValueName)=0
      lResult=1
    EndIf
    RegCloseKey_(hKey)
  EndIf 
  ProcedureReturn lResult
EndProcedure
Image Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

wow you give him a big pole, paul! i thought just giving him the keyword should be enough for the likes of him :-)
( 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... )
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

blueznl wrote:wow you give him a big pole, paul! i thought just giving him the keyword should be enough for the likes of him :-)
Funny part is, is that the above code is already listed in the first post..

With error checking..

- np
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1287
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Actually... if you want the pole and the whole tackle box, simply download API_Guide.

It has hundreds of API calls (all grouped in categories) along with VB source code examples that are extremely easy to convert to PureBasic.
Image Image
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

I've got not only the fishing pole, tackle box, but I have the whole damn
fishing store.. ;)

API-Guide
API-Viewer
Platform SDK (its beautiful... any api i type in the PB ide, i just hit Alt-F1)
Win32.hlp (new and old) (this one is of course just F1)
Microsoft MSDN Library (latest version)

;)

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

Post by NoahPhense »

Ok, so I got these, they should be good for now:

Debug #REG_SZ
Debug #REG_DWORD
Debug #REG_BINARY

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

Post by PB »

> 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...
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:> 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...
You don't have to:

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 
Here's one for the key and all sub keys:

Code: Select all

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
- np
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

hey! paul provided the fishing rod, but i provided the hook! or at least i was quicker mentioning the right api... i never get the credit, whehehehehehehehehehehe!

(frustrated, my 3 weeks onld asus k8n-e mainboard suddenly died, first a drive, then a video card, now a mainboard, what's next?)
( 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... )
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1287
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

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:
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

blueznl wrote:hey! paul provided the fishing rod, but i provided the hook! or at least i was quicker mentioning the right api... i never get the credit, whehehehehehehehehehehe!

(frustrated, my 3 weeks onld asus k8n-e mainboard suddenly died, first a drive, then a video card, now a mainboard, what's next?)
I feel for you man. I'll stay with my laptops.. ;)

But I do have an upgraded PII running my internet domain here.. lol

It's got a WD 250gb in it.. even running the harddrive overlay on it and
512 memory. has web server, ftp server, mail server, mysql, etc..

Haven't rebooted it in a few weeks..


- np
Post Reply