Page 2 of 3

Posted: Sat Feb 26, 2005 10:29 am
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
;


Posted: Sat Feb 26, 2005 12:03 pm
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.

Posted: Sat Feb 26, 2005 12:36 pm
by blueznl
oh i see, i think you are looking for RegDeleteValue_()

Posted: Sat Feb 26, 2005 2:09 pm
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

Posted: Sat Feb 26, 2005 4:43 pm
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

Posted: Sat Feb 26, 2005 6:51 pm
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 :-)

Posted: Sat Feb 26, 2005 7:36 pm
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

Posted: Sat Feb 26, 2005 7:49 pm
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.

Posted: Sat Feb 26, 2005 7:53 pm
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

Posted: Sat Feb 26, 2005 9:11 pm
by NoahPhense
Ok, so I got these, they should be good for now:

Debug #REG_SZ
Debug #REG_DWORD
Debug #REG_BINARY

- np

Posted: Sun Feb 27, 2005 1:30 am
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...

Posted: Sun Feb 27, 2005 1:39 am
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

Posted: Sun Feb 27, 2005 3:05 am
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?)

Posted: Sun Feb 27, 2005 3:11 am
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:

Posted: Sun Feb 27, 2005 3:14 am
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