Sign in to follow this  
Followers 0
robinsiebler

Registry search weirdness

10 posts in this topic

#1 ·  Posted (edited)

I am trying to search the registry for a specific key (which always exists). I am searching HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall. The full key I am looking for ends in a random GUID, like so: [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall{1D3D955D-98EF-4CC4-B142-22F52BF79124}].

On one particular machine, the below code fails to find the key about 3/4 of the time. If I step through the code, it almost always finds it. I don't know what the problem is (timing maybe) or how to fix it. Any insight would be appreciated.

I figured out more of the problem, but still not why. When it fails, $sDisplay is an empty string, even though it is in the right key.

$UninstallString = FindUninstallString($Product)

; Find the Uninstall String in the registry
Func FindUninstallString($sSearch)
$sBase = "HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall"
$iEval = 1

While 1
$sUninst = ""
$sDisplay = ""
$sCurrent = RegEnumKey($sBase, $iEval)
If @error Then ExitLoop
     $sKey = $sBase & "" & $sCurrent
$sDisplay = RegRead($sKey, "DisplayName")

If StringRegExp($sDisplay, ".*" & $sSearch & ".*") Then
$sUninst = RegRead($sKey, "UninstallString")
If $sUninst Then
Return $sUninst
EndIf
EndIf
$iEval += 1
WEnd
EndFunc ;==>FindUninstallString
Edited by robinsiebler

Share this post


Link to post
Share on other sites



You state that when it fails $sDisplay is empty. Does that key always have a DisplayName value? I would suggest doing some simple checks first. Put a MsgBox right after you define $sKey, and confirm that this is what you expect it to be. If it is, I would look at some of the other values under that key (DisplayVersion, InstallDate, etc.) and see if you can properly call them out as well.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't know if it is an AutoIt bug or what, but when the program gets to the key containing the value I want it either correctly reads the DisplayName or it shows an empty string for the DisplayName. The same thing happens for any other value under that key. It either works or fails miserably. And it is intermittent. It will work X times, then suddenly fail X times and then just as suddenly start working again.

Edited by robinsiebler

Share this post


Link to post
Share on other sites

What OS and bit version are you using? Also, what are the @error values for the RegRead calls? An empty string is returned when there is an error.

Adam

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

WinXP Embedded Standard (32-bit) and the error code is 1 (1 if unable to open requested key).

Edited by robinsiebler

Share this post


Link to post
Share on other sites

Rather than stepping through it, have you just tried adding a sleep or two?

Share this post


Link to post
Share on other sites

What value are you looking to find? Are you sure there's actually a display name value in there?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I've tried adding sleep statements and even adding the regread more than once, it doesn't make a difference. And yes, the value is always there, I can see it in the registry plain as day. I'm looking for a DisplayName - HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall{Some Random GUID}DisplayName (which should equal "Citrix HDX RealTime Media Engine").

Edited by robinsiebler

Share this post


Link to post
Share on other sites

When I run the script with this line:

$sKey = $sBase & "" & $sCurrent

The $sKey value for all $sCurrent values equals something like this:

HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstallAdobe Flash Player ActiveX

Maybe try it without the & "" in there and see if it picks it up better.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

That seems to have done the trick. But the bug is intermittent, so I will have to test for a few days to me sure.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0