Registry Module (windows only)

Share your advanced PureBasic knowledge/code with the community.
GJ-68
User
User
Posts: 32
Joined: Sun Jun 23, 2013 1:00 pm
Location: France (68)

Re: Registry Module (windows only)

Post by GJ-68 »

OpenKey()
error = RegDeleteTree(hKey) ;<< IMA Error here.
RegDeleteTree is exported from Advapi32.dll only in Windows Vista and higher.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Registry Module (windows only)

Post by ts-soft »

you are right.

RegDeleteKeyEx requires: Windows Vista, Windows XP Professional x64 Edition +
RegDeleteTree requires: Windows Vista +
RegSetValueEx requires: Windows 2000 Professional +

I will add some check and workarounds in the next days.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
GJ-68
User
User
Posts: 32
Joined: Sun Jun 23, 2013 1:00 pm
Location: France (68)

Re: Registry Module (windows only)

Post by GJ-68 »

For Windows XP, use this:

Code: Select all

Procedure.l RegDeleteTree(hTopKey.i, sSubKey.s)
  Protected hKey.i, RetCode.l, dwSize.l, sBuf.s

  RetCode = RegOpenKeyEx_(hTopKey, sSubKey, 0, #KEY_ENUMERATE_SUB_KEYS, @hKey)
  If RetCode = #ERROR_SUCCESS
    sBuf = Space(#MAX_PATH)
    Repeat
      dwSize = #MAX_PATH
      RetCode = RegEnumKeyEx_(hKey, 0, sBuf, @dwSize, 0, 0, 0, 0)
      If RetCode = #ERROR_SUCCESS : RegDeleteTree(hKey, sBuf) : EndIf
    Until RetCode
    RegCloseKey_(hKey)
    RetCode = RegDeleteKey_(hTopKey, sSubKey)
  EndIf
  ProcedureReturn RetCode
EndProcedure
Works fine on XP SP3.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: Registry Module (windows only)

Post by sec »

@ts-soft
Should you delete the key in example? it's deleted value only :D
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Registry Module (windows only)

Post by ts-soft »

sec wrote:@ts-soft
Should you delete the key in example? it's deleted value only :D
This is okay, i won't delete a key with name "ts-soft". It is required in a feature Software by me :mrgreen:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
RomanR
User
User
Posts: 16
Joined: Wed Jul 11, 2012 3:54 pm

Re: Registry Module (windows only)

Post by RomanR »

Hi ts-soft,

to get an error while reading recursively is not a problem (therfore the "If Not RegReturn\ERROR" part). It's ok if I am not allowed to read some subkeys (the ways of mircosoft :wink: are mysterious).
The only problem is, if I am not allowed to read a particular subkey (and it's not the last like "Properties") all further calls of e.g. CountSubValues have RegValue/ERROR still set to #True!

On my system the subkey "#HKEY_LOCAL_MACHINE SYSTEM\CurrentControlSet\Control\Class\{4D36E97D-E325-11CE-BFC1-08002BE10318}\0021" is protected (-> error access violation).
All following subkeys "...\0022", "...\0023", "...\0024", "...\0025" ... (with exception of "Properties" which is the last) are not protected. But with current Version (1.3.3) I get access violation error for them too.

There are two methods to get correct results are:
* to clear the structure "RegValue" before calling CountSubValues,
or
* to clear the structure "RegValue" in the OpenKey/OpenKeyS Macros as I mentioned.

I just shortened my example a bit for shorter code, but I'm reading through all subkeys of "#HKEY_LOCAL_MACHINE SYSTEM\CurrentControlSet\Control\Class". So if you iterate through all classes and get the first error at "#HKEY_LOCAL_MACHINE SYSTEM\CurrentControlSet\Control\Class\{...}\Properties" you don't get results for the other classes ...
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: Registry Module (windows only)

Post by jassing »

-- removed, use ts-soft's --
Last edited by jassing on Mon Sep 02, 2013 7:56 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Registry Module (windows only)

Post by ts-soft »

Thx for all you're replies and code :D

Update:
History wrote:; Version 1.4, Sep 02, 2013
; fixed Clear Resultstructure
; + compatibility to WinXP
Please test it, special on winxp, i can't test it at the moment.

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
GJ-68
User
User
Posts: 32
Joined: Sun Jun 23, 2013 1:00 pm
Location: France (68)

Re: Registry Module (windows only)

Post by GJ-68 »

@ts-soft:

Not tested but your XP_DeleteTree can not work, it deletes only one level of subkeys.
My code calls RegDeleteTree recursively.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Registry Module (windows only)

Post by ts-soft »

:oops:

fixed
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ClueLess
Enthusiast
Enthusiast
Posts: 345
Joined: Sun Jan 11, 2009 1:04 am

Re: Registry Module (windows only)

Post by ClueLess »

I may be using it wrong, but get an error on line 50: Sinxtax Error
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Registry Module (windows only)

Post by ts-soft »

ClueLess wrote:I may be using it wrong, but get an error on line 50: Sinxtax Error
You require PB 5.20 and Higher!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Registry Module (windows only)

Post by Crusiatus Black »

in WriteValue, RegSetValueEx requires a pointer to the data to be set, not the actual value;

Code: Select all

      Case #REG_DWORD
	    Protected lval.l = Val(Value)
        error = RegSetValueEx_(hKey, ValueName, 0, #REG_DWORD, @lval, SizeOf(Long))
       
      Case #REG_QWORD
	    Protected qval.q = Val(Value)
        error = RegSetValueEx_(hKey, ValueName, 0, #REG_QWORD, @qval, SizeOf(Quad))
It will instead try to interpret the value as pointer and result in a 'invalid access to memory location'
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
rudz
User
User
Posts: 35
Joined: Sun Mar 21, 2010 6:59 am
Location: Denmark
Contact:

Re: Registry Module (windows only)

Post by rudz »

Very nice, needed one of those and had just started making one myself, this saves me the time :)
AMD FX-8350 @ ~4.8GHz | 8GB Corsair DDR3-SDRAM @ 1800Mhz | 7even Ult & Manjaro 0.8.7.1 | PB 5.3
Web: rudz.dk
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Registry Module (windows only)

Post by ricardo »

How to WriteValue as #REG_DWORD with this library? I want to use this because the WOW64 option

I tried with no success

Code: Select all

WriteValue(#HKEY_CURRENT_USER,"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION","WebGadget.exe","10001",#REG_DWORD)

Any help are welcome
ARGENTINA WORLD CHAMPION
Post Reply