Page 2 of 7

Re: Registry Module (windows only)

Posted: Sun Sep 01, 2013 7:50 pm
by GJ-68
OpenKey()
error = RegDeleteTree(hKey) ;<< IMA Error here.
RegDeleteTree is exported from Advapi32.dll only in Windows Vista and higher.

Re: Registry Module (windows only)

Posted: Sun Sep 01, 2013 8:06 pm
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.

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 6:15 am
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.

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 7:07 am
by sec
@ts-soft
Should you delete the key in example? it's deleted value only :D

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 7:34 am
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:

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 4:23 pm
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 ...

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 5:27 pm
by jassing
-- removed, use ts-soft's --

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 5:55 pm
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

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 7:41 pm
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.

Re: Registry Module (windows only)

Posted: Mon Sep 02, 2013 7:49 pm
by ts-soft
:oops:

fixed

Re: Registry Module (windows only)

Posted: Sun Sep 08, 2013 5:04 am
by ClueLess
I may be using it wrong, but get an error on line 50: Sinxtax Error

Re: Registry Module (windows only)

Posted: Sun Sep 08, 2013 8:02 am
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!

Re: Registry Module (windows only)

Posted: Fri Jan 10, 2014 3:56 am
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'

Re: Registry Module (windows only)

Posted: Fri Jan 10, 2014 7:05 am
by rudz
Very nice, needed one of those and had just started making one myself, this saves me the time :)

Re: Registry Module (windows only)

Posted: Fri Jun 27, 2014 2:51 am
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