Jump to content

Having an issue with RegRead


jerseyzuks
 Share

Recommended Posts

Working on a little project to make sure the machines in our Lab have the expected version of a list of software applications before the testers use them for testing

I start off by declaring a global variable

Global $evVisio = "14.0.4763.1000"

Then I call this function...

Func Visio ()
   $softwareCheck = "Microsoft Visio Viewer"
   Call ("FindVersion")
   If $installVersion = $evVisio Then
   FileWriteLine($file, "PASS - Visio has the correct version " & $installVersion)
   Else
   FileWriteLine($file, "FAIL - Visio does not have the correct version. The current version is " & $evVisio & " this machine has " & $installVersion)
   EndIf
EndFunc

Which then calls this function... (message boxes just give me an idea of what is going on, and will be commented out)

Func FindVersion ()
   $index = 1
   $keyroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
   $installVersion = ""
   $subkey = "START"; This sets the variable because "" will make the While loop exit
   While $subkey <> ""
      $subkey = RegEnumKey($keyroot, $index)
      $DisplayName = RegRead($keyroot & "\" & $subkey, "DisplayName") 
      MsgBox (0, $subkey,  $DisplayName)
      If StringInStr(RegRead($keyroot & "\" & $subkey, "DisplayName"), $softwarecheck) Then
         $installVersion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $subkey, "DisplayVersion")
         $subkey = ""    ; Force the While to exit
         If $installVersion <> "" then 
            ExitLoop
         Endif
      EndIf
   $index = $index + 1
   WEnd
   Return $installVersion
EndFunc

This works on the first 25 or so applications flawlessly, and it all gets written to a quick little report that the tester can glance at and proceed.  

I have a few that are returning a "", so it's throwing an error.  I included the message boxes for troubleshooting, and realized that it is skipping over the subkeys that I am looking for.

What I noticed is that the ones it is skipping over have key names like {4957C351-2399-47D6-B857-81FBB67E28DB}

Thanks in advance for your help! 

Link to comment
Share on other sites

  • Moderators

Hi, jerseyzuks. I use the attached for uninstalling apps. It is pretty good at returning only what you ask for, and has a right-click uninstall feature. Credit goes to Big Daddy (I think, its been so many years).

Enumerate Local Apps with Uninstall.au3

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

This is the exact code that isn't working...

Func SecureZip ()
   $softwareCheck = "SecureZIP"
   Call ("FindVersion")
      If $installVersion = $evSecureZip Then
      FileWriteLine($file, "PASS - SecureZip has the correct version " & $installVersion)
   Else
      FileWriteLine($file, "FAIL - SecureZip does not have the correct version. The current version is " & $evSecureZip & " this machine has " & $installVersion) 
   EndIf


EndFunc

And the result it returns is...

FAIL - SecureZip does not have the correct version. The current version is 12.51.0004 this machine has

Link to comment
Share on other sites

If I call a handful of them back to back, I get something that looks like this for the results

PASS - Silverlight has the correct version 5.1.20513.0
PASS - Adobe Flash has the correct version 11.6.602.168
PASS - Adobe Shockwave has the correct version 11.6.1.629
PASS - Java has the correct version 6.0.450
PASS - Visio has the correct version 14.0.4763.1000
PASS - Adobe Reader has the correct version 11.0.01
PASS - Lotus Notes has the correct version 8.53.11258
FAIL - McAfee AntiSpyware does not have the correct version. The current version is 8.7.0.147 this machine has 8.7.0.129
FAIL - SecureZip does not have the correct version. The current version is 12.51.0004 this machine has

Now in this case McAfee was set to fail, which it did (this machine has a slightly older version of McAfee).  SecureZip should have passed, but it didn't

Link to comment
Share on other sites

If I were you, I'd rewrite those functions and elimnate all the duplicated code by using one function and a list of software to check against. Right now all of your version check functions are doing the exact same thing and only the name of the software is being changed. You're using a lot of unnecessary global variables as well.

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

Link to comment
Share on other sites

If I were you, I'd rewrite those functions and elimnate all the duplicated code by using one function and a list of software to check against. Right now all of your version check functions are doing the exact same thing and only the name of the software is being changed. You're using a lot of unnecessary global variables as well.

 

I'm not a programmer by any stretch of the imagination, so I appologize for the sloppy coding

Link to comment
Share on other sites

Take in account the x86 key and the x64 key if you are on a 64 bit OS.

x64 is HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall

x86 is HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall

 

I took that into consideration, but I can manually locate it in HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall

The script cannot

Link to comment
Share on other sites

The issue is with your While Loop.

Try this:

Func FindVersion ()
    $index =1
    $keyroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Global $installVersion = ""
    $subkey = "START"; This sets the variable because "" will make the While loop exit
        Do
        $subkey = RegEnumKey($keyroot, $index)
        $DisplayName = RegRead($keyroot & "\" & $subkey, "DisplayName")
        MsgBox (0, $subkey,  $DisplayName)
        If StringInStr(RegRead($keyroot & "\" & $subkey, "DisplayName"), $softwarecheck) Then
        $installVersion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $subkey, "DisplayVersion")
            EndIf
            $index = $index + 1
          Until     $subkey = ""    
        

Return $installVersion
EndFunc

I was then presented with the following result:

PASS - Visio has the correct version 14.0.4763.1000

edit: Grammar

Edited by allSystemsGo
Link to comment
Share on other sites

The issue is with your While Loop.

Try this:

Func FindVersion ()
    $index =1
    $keyroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Global $installVersion = ""
    $subkey = "START"; This sets the variable because "" will make the While loop exit
        Do
        $subkey = RegEnumKey($keyroot, $index)
        $DisplayName = RegRead($keyroot & "\" & $subkey, "DisplayName")
        MsgBox (0, $subkey,  $DisplayName)
        If StringInStr(RegRead($keyroot & "\" & $subkey, "DisplayName"), $softwarecheck) Then
        $installVersion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $subkey, "DisplayVersion")
            EndIf
            $index = $index + 1
          Until     $subkey = ""    
        

Return $installVersion
EndFunc

I was then presented with the following result:

PASS - Visio has the correct version 14.0.4763.1000

edit: Grammar

 

I commented out my FindVersion function, and substituted yours (commenting out the message box)

The results I recieved were

PASS - Silverlight has the correct version 5.1.20513.0

PASS - Adobe Flash has the correct version 11.6.602.168

PASS - Adobe Shockwave has the correct version 11.6.1.629

PASS - Java has the correct version 6.0.450

PASS - Visio has the correct version 14.0.4763.1000

PASS - Adobe Reader has the correct version 11.0.01

PASS - Lotus Notes has the correct version 8.53.11258

FAIL - McAfee AntiSpyware does not have the correct version. The current version is 8.7.0.147 this machine has 8.7.0.129

FAIL - SecureZip does not have the correct version. The current version is 12.51.0004 this machine has

Link to comment
Share on other sites

You could always use FileGetVersion on the executable for the program if you can see where it's installed.

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

Link to comment
Share on other sites

  • Moderators

Or use WMI:

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$aItems = $WMI.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($aItems) then
   For $element In $aItems
       MsgBox(0, "", "Product: " & $element.Name & @CRLF & @CRLF & $element.Version)
   Next
Endif

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

 

OK, now I am beyond confused

Why wouldn't this work?

Func SecureZipReg ()
   Global $SecureZip = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4957C351-2399-47D6-B857-81FBB67E28DB}", "DisplayName")
   MsgBox (0, "", $SecureZip)
EndFunc

Does that return what you would expect? Is this the only key that returns unexpected results?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...