Page 1 of 1 1
Topic Options
#196632 - 2009-11-10 05:34 PM KEYEXIST & READVALUE in X64
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I am having to interact with More x64 systems, XP64 and VISTA and have unearthed a very frustrating problem I am hoping someone can help me with...
As a pre-install check for an application installer I need to check in this example whether .NET 3.5 SP1 is present.

On 32bit no problem, on 64bit neither KEYEXIST nor READVALUE returns what is expected... e.g.

IF keyexist("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}")=0

or

If InStr(ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}","DisplayName"),'3.5')=0

then Not installed...

I am assuming it is some type of security setting but I have no clue how to circumvent it !

Suggestions Welcome. Currently I have to bypass the check on x64 !!

Top
#196633 - 2009-11-10 05:44 PM Re: KEYEXIST & READVALUE in X64 [Re: MACE]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
See if turning the WOW64AlternateRegView on helps.

$RC=setoption("WOW64AlternateRegView","on")

Top
#196646 - 2009-11-11 11:55 AM Re: KEYEXIST & READVALUE in X64 [Re: Allen]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
No, no difference I am afraid. Can't get anything out of this part of the Registry on X64 as illustrated.
On other things, eg classes, have been able to read and write values.
In HKCU\Software, can read and write.

The frustration comes when trying to get values as illustrated, yet...
 Code:
break on
;test for X64
$ = SetOption("WrapAtEOL","ON")
If @onwow64=1
 Dim $E,$T,$UN
 $UN="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
 ? "Writing REG_SZ value 'Testing' as test data to:"
 ? $UN+'TestData'
 $E=writevalue($un,'TestData','Testing','REG_SZ')
 ? 'Write Returncode='+$E+' '+@serror+@crlf
 $T=readvalue($un,'TestData')
 $E=@error
 ? 'Reading back value from registry = '+$T
 ? 'Read Returnerror='+$E+' '+@serror+@crlf
 $E=delvalue($un,'TestData')
 ? 'Deleting Test Entry returned:'+$E+' '+@serror+@crlf
 $UN="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}"
 ? $UN
 $T=ReadValue($UN,"DisplayName")
 $E=@error
 ? "Reading 'DisplayName' = "+$T
 ? 'Reading Errorcode = '+$E+' '+@serror+@crlf
Else
 ? 'Not a x64 Test machine !'
Endif
? 'Press any key to exit...'
get $


This works fine... Until I look for 'usefull' data and I get error 2 Not Found.

I regularly use KIX code as a wrapper to deploy via logon script or update script with default values, applications not conforming to the Microsoft MSI deployment methods. Now I can't test safely whether X is installed without reverting to lists of potential paths and looking for file names and dates !


Edited by MACE (2009-11-11 12:17 PM)

Top
#196648 - 2009-11-11 12:19 PM Re: KEYEXIST & READVALUE in X64 [Re: MACE]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Check your KiXtart version.

I've just tried this:
 Code:
Break ON

"KiXtart version: "+@KIX+@CRLF
For Each $sState in Split("ON OFF")
   $=SetOption("WOW64AlternateRegView",$sState)
   "With WOW64AlternateRegView "+$sState+" I get '"+ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
Uninstall\{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}","DisplayName")+"'"+@CRLF
Next


And I get:
 Quote:
KiXtart version: 4.61 Beta 1
With WOW64AlternateRegView ON I get 'Microsoft .NET Framework 3.5 SP1'
With WOW64AlternateRegView OFF I get ''


Edited by Glenn Barnas (2009-11-21 06:06 PM)
Edit Reason: broke long line

Top
#196653 - 2009-11-11 10:40 PM Re: KEYEXIST & READVALUE in X64 [Re: Richard H.]
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
Try this and let me know your results...
 Code:
break on
;test for X64
If @onwow64=1
 $ = SetOption("WrapAtEOL","ON")
 $ = SetOption("WOW64AlternateRegView","on") 
 Dim $E,$T,$UN,$SK,$V
 $UN="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
 $SK='{Test-Data}'
 $V='DisplayName'

 ? "Writing REG_SZ value 'Testing' as test data to:"
 ? $UN+$SK+','+$V
 $E=writevalue($un+$SK,$V,'Testing','REG_SZ')
 ? 'Write Returncode='+$E+' '+@serror+@crlf

 $T=readvalue($un+$SK,$V)
 $E=@error
 ? 'Reading back value from registry = '+$T
 ? 'Read Returnerror='+$E+' '+@serror+@crlf

? 'Use REGEDIT to locate '+$SK
? 'Now press any key to continue...'+@crlf
Get $

$UN2=join(split($UN,'Microsoft'),'Wow6432Node')
? 'Manually searched the registry...'
? 'Actual registry path being used turned out to be:'+@crlf+$UN2+@crlf


$E=deltree($un+$SK)
? 'Deleting:'+$UN+$SK+@crlf+'Returned:'+$E+' '+@serror+@crlf

$E=deltree($un2+$SK)
? 'Deleting:'+$UN2+$SK+@crlf+'Returned:'+$E+' '+@serror+@crlf

? "Deleting 'Microsoft' key removed the 'Wow6432Node' key !"+@crlf

Else
 ? 'Not a x64 Test machine !'
Endif
? 'Press any key to exit...'
get $


Your code hilighted MY problem...
Because x64 the update test for KIX had not installed 4.6 onto the x64 machines so still only 4.53 therefore self defeating issue as no SetOption("WOW64AlternateRegView","on") in older version!
Manually updated to 4.6 and now I get the desired results.
Looks like the first test I need do is the KIX version!

Thanks for the help :-)



Edited by MACE (2009-11-11 10:45 PM)

Top
#196656 - 2009-11-12 12:32 AM Re: KEYEXIST & READVALUE in X64 [Re: MACE]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Make sure you are using 4.61... 4.60 is bit of bugger. \:\)
Top
#196807 - 2009-11-21 06:04 PM Re: KEYEXIST & READVALUE in X64 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
I've been playing around with some registry manipulation on an X64 system and am finding some odd things as well.

With AlternateRegView OFF, all registry functions work as expected, but write to the WOW6432Node part of the registry. I can create a key, write, modify, and delete values, delete keys, and delete the entire tree.

With AlternateRegView ON, however, things get a bit funky.
  • WriteValue: works, writing in the 64b part of the registry. Both create and modify work.
  • DelValue: works - the value is removed as expected
  • KeyExist: works - reports the presents/absence of the key
  • EnumKey: works - can enumerate the keys that exist
  • EnumValue: works - can enumerate values that exist in a key
  • DelKey: fails - I cannot delete a key at all, it reports Error 2 - not found.
  • DelTree: Partially fails - it appears to delete the entire tree contents, but does not remove the root of the key. It then reports an error 2 - not found.
Obviously, this only affects scripts running on 64-bit systems, but we're finding more and more of them, so the problem will only become worse.

It seems that some of the code between DelKey and DelTree is shared. DelKey won't work at all against the 64b registry - seems like it's not honoring the AlternateRegView setting. DelTree succeeds in deleting all subkeys and values, but then fails when trying to remove the root of the key path. If it's calling the same logic as DelKey, it makes sense that it would fail to delete and report Error 2.

I have tested with Kix 4.60 and 4.61 with identical results. I'd like some others here to confirm my results. If it is confirmed, we can open a bug report.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196808 - 2009-11-21 06:09 PM Re: KEYEXIST & READVALUE in X64 [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Here's my test script. Run KIX32 REGTEST.KIX to run with AlternateRegView OFF, or KIX32 REGTEST.KIX $SET=ON to turn it on.


Break On
 
; set the default value for the Alternate Registry View 
If $SET = '' $SET = 'OFF' EndIf
 
; set the alternate registry view 
$ = SetOption('WOW64AlternateRegView', $SET)
 
$DoWait = 0		; set to 1 to pause after each reg change to manually review 
 
'Registry write/delete test on a ' IIf(InStr('%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%', 'AMD64'), 64, 32) ' bit system.'  ?
'Kix version: ' @KIX ' ' ?
'Alternate Reg View: ' SetOption('WOW64AlternateRegView')  ?
 
; Does it exist? 
If KeyExist('HKLM\SOFTWARE\TEST')
  'Registry root exists' ?
Else
  'Registry root does not exist.' ?
EndIf
 
 
; Create some reg values 
'Creating reg values:' ?
$ = WriteValue('HKLM\SOFTWARE\TEST\Test','TestVal','This is a test','REG_SZ')
' ' @SERROR ?
$ = WriteValue('HKLM\SOFTWARE\TEST\Test2','TestVal','This is another test','REG_SZ')
' ' @SERROR ?
' Read Value 1: ' ReadValue('HKLM\SOFTWARE\TEST\Test','TestVal') ?
' Read Value 2: ' ReadValue('HKLM\SOFTWARE\TEST\Test2','TestVal') ?
 
; Does it exist? 
If KeyExist('HKLM\SOFTWARE\TEST')
  'Registry root exists' ?
Else
  'Registry root does not exist.' ?
EndIf
 
If $DoWait 'Press any key: ' Get $ ? Else Sleep 2 EndIf
 
? 'Testing EnumKey:' ?
$I = 0
$Val = EnumKey('HKLM\SOFTWARE\TEST', $I)
While Not @ERROR
  $I + 1 '. ' $Val ?
  $I = $I + 1
  $Val = EnumKey('HKLM\SOFTWARE\TEST', $I)
Loop
 
? 'Testing EnumValue:' ?
$I = 0
$Val = EnumValue('HKLM\SOFTWARE\TEST\Test2', $I)
While Not @ERROR
  $I + 1 '. ' $Val ?
  $I = $I + 1
  $Val = EnumValue('HKLM\SOFTWARE\TEST\Test2', $I)
Loop
?
 
If $DoWait 'Press any key: ' Get $ ? Else Sleep 2 EndIf
 
; Delete a reg value 
'Deleting a reg value:' ?
$ = DelValue('HKLM\SOFTWARE\TEST\Test','TestVal')
' ' @SERROR ?
' Read Value 1: ' ReadValue('HKLM\SOFTWARE\TEST\Test','TestVal') ?
' ' @SERROR ?
' Read Value 2: ' ReadValue('HKLM\SOFTWARE\TEST\Test2','TestVal') ?
' ' @SERROR ?
 
If $DoWait 'Press any key: ' Get $ ? Else Sleep 2 EndIf
 
; Delete a reg Key - is empty, so should work 
'Deleting an empty reg key: ' ?
$ = DelKey('HKLM\SOFTWARE\TEST\Test')
' ' @SERROR ?
' Read Value 1: ' ReadValue('HKLM\SOFTWARE\TEST\Test','TestVal') ?
' ' @SERROR ?
' Read Value 2: ' ReadValue('HKLM\SOFTWARE\TEST\Test2','TestVal') ?
' ' @SERROR ?
 
If $DoWait 'Press any key: ' Get $ ? Else Sleep 2 EndIf
 
; Del the entire tree 
'Deleting the entire TEST reg tree:' ?
$ = DelTree('HKLM\SOFTWARE\TEST')
' ' @SERROR ?
' Read Value 1: ' ReadValue('HKLM\SOFTWARE\TEST\Test','TestVal') ?
' ' @SERROR ?
' Read Value 2: ' ReadValue('HKLM\SOFTWARE\TEST\Test2','TestVal') ?
' ' @SERROR ?
 
; Does it exist? 
If KeyExist('HKLM\SOFTWARE\TEST')
  'Registry root exists' ?
Else
  'Registry root does not exist.' ?
EndIf
 
 
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196811 - 2009-11-23 05:09 AM Re: KEYEXIST & READVALUE in X64 [Re: Glenn Barnas]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
script was run as admin with UAC on.

OFF
 Code:
Registry write/delete test on a 64 bit system.
Kix version: 4.61
Alternate Reg View: OFF
Registry root does not exist.
Creating reg values:
 The operation completed successfully.
 The operation completed successfully.
 Read Value 1: This is a test
 Read Value 2: This is another test
Registry root exists

Testing EnumKey:
1. Test
2. Test2

Testing EnumValue:
1. TestVal

Deleting a reg value:
 The operation completed successfully.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2: This is another test
 The operation completed successfully.
Deleting an empty reg key:
 The operation completed successfully.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2: This is another test
 The operation completed successfully.
Deleting the entire TEST reg tree:
 The operation completed successfully.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2:
 The system cannot find the file specified.
Registry root does not exist.
 


ON
 Code:
Registry write/delete test on a 64 bit system.
Kix version: 4.61
Alternate Reg View: ON
Registry root does not exist.
Creating reg values:
 The operation completed successfully.
 The operation completed successfully.
 Read Value 1: This is a test
 Read Value 2: This is another test
Registry root exists

Testing EnumKey:
1. Test
2. Test2

Testing EnumValue:
1. TestVal

Deleting a reg value:
 The operation completed successfully.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2: This is another test
 The operation completed successfully.
Deleting an empty reg key:
 The system cannot find the file specified.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2: This is another test
 The operation completed successfully.
Deleting the entire TEST reg tree:
 The system cannot find the file specified.
 Read Value 1:
 The system cannot find the file specified.
 Read Value 2:
 The system cannot find the file specified.
Registry root exists

Top
#196813 - 2009-11-23 12:02 PM Re: KEYEXIST & READVALUE in X64 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Thanks - you can see in the first run that the registry key is gone at the end, while in the second run it still exists. If you run RegEdit, you can see that the first test creates the root key in the wow6432node subkey, while the second test creates it directly in the SOFTWARE key.

If I had added another "If KeyExist" code block after deleting the first key, you'd have also seen that the Test subkey is deleted with the setting OFF but is not when the setting is ON.

BTW - you'll need to manually delete the HKLM\SOFTWARE\TEST reg key after the second test. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202126 - 2011-05-06 12:37 PM Re: KEYEXIST & READVALUE in X64 [Re: Glenn Barnas]
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Hmm.. thanks for the report, I will have a look!

Ruud

Top
#202278 - 2011-05-20 03:43 PM Re: KEYEXIST & READVALUE in X64 [Re: Glenn Barnas]
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Just to let you know I've investigated this issue and found the problem.
I'll fix this in the next update.
Thanks for the report!

Ruud

Top
#207491 - 2013-07-25 01:40 PM Re: KEYEXIST & READVALUE in X64 [Re: Ruud van Velsen]
green78 Offline
Fresh Scripter

Registered: 2007-05-02
Posts: 34
Apologies. It is working properly... there was just an "invisible" space after the DSN name.

Edited by green78 (2013-07-25 04:57 PM)
Edit Reason: My bad

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 676 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.064 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org