#196632 - 2009-11-1005:34 PMKEYEXIST & READVALUE in X64
MACEMACE
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 !!
MACEMACE
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 !
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-2106:06 PM) Edit Reason: broke long line
#196653 - 2009-11-1110:40 PMRe: KEYEXIST & READVALUE in X64
[Re: Richard H.]
MACEMACE
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!
Glenn BarnasGlenn Barnas 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!
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
Glenn BarnasGlenn Barnas 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!