Jump to content

help using RegEnumKey


dcoggie
 Share

Recommended Posts

This topic has given me an idea, in addition to my _UninstallList () function.

Can you try the following code, it uses my new function _IsInstalled which checks if an application is installed, and also checks the version.

#include <Misc.au3>
#Include <Date.au3>


; #EXAMPLE ======================================================================================================================
Local $aApps = [["Microsoft Silverlight", "5", 0], ["PDFCreator", 0, 0], ["Java.+?\d+ Update \d", "8.0.660.18", 3], ["Adobe flash Player", "18", 0]]

Local $iIsInstalled, $sRes, $sUTP
For $i = 0 To UBound($aApps) - 1
    $iIsInstalled = _IsInstalled($aApps[$i][0], $aApps[$i][1], $aApps[$i][2])
    If $iIsInstalled Then
        $sRes = " is installed."
        Switch @extended
            Case -1
                $sUTP = " An older version than '" & $aApps[$i][1] & "' is installed."
            Case 1
                $sUTP = " A newer version than '" & $aApps[$i][1] & "' is installed."
            Case 0
                $sUTP = ""
        EndSwitch
    Else
        $sRes = " is not installed."
    EndIf
    ConsoleWrite($aApps[$i][0] & $sRes & $sUTP & @CRLF)
Next
; ===============================================================================================================================





; #FUNCTION# ====================================================================================================================
; Name ..........: _IsInstalled
; Description ...: Checks if an application is installed on the local computer.
; Syntax ........: _IsInstalled($sAppname[, $sMinVersion = 0[, $iSearchMode = 0]])
; Parameters ....: $sAppname            - Application name or partial name (depending of $iSearchMode value).
;                  $sMinVersion         - [optional] Minimum version to check. Default is 0 (don't check for the version).
;                  $iSearchMode         - [optional] Search mode. Default is 0.
;                                            0 : Match string from the start.
;                                            1 : Match any substring.
;                                            2 : Exact string match.
;                                            3 : $sAppname is a regular expression
; Return values .: Success  - 1
;                  Failure  - 0
; Author ........: jguinch
; Remarks .......: on success, @extended is set to:
;                      0   - The specified version is installed (or no version checked if $sMinVersion^= 0)
;                      1   - A newer version is installed
;                     -1   - An older version is installed
; ===============================================================================================================================
Func _IsInstalled($sAppname, $sMinVersion = 0, $iSearchMode = 0)
    Local $aAppList = _UninstallList("DisplayName", $sAppname, "DisplayVersion", $iSearchMode)
    If Not $aAppList[0][0] Then Return 0
    Local $iExtended = -1

    For $i = 1 To $aAppList[0][0]
        $sAppName = $aAppList[$i][2]
        $sVersion = $aAppList[$i][4]

        If StringRegExp($sAppName, "\d+\h*(\.\d+)+$") Then
            $aAppInfo = StringRegExp($sAppName, "(.+?)\h*(\d+(?:\.\d+)+)$", 1)
            $sAppName = $aAppInfo[0]
            If $sVersion = "" Then $sVersion = $aAppInfo[1]
        EndIf

        If $sMinVersion Then
            $iVersionComp = _VersionCompare($sVersion, $sMinVersion )
            If $iVersionComp = 0 And $iExtended = -1 Then $iExtended = 0
            If $iVersionComp = 1 And $iExtended <= 0 Then $iExtended = 1
        Else
            $iExtended = 0
        EndIf
    Next
    Return SetError(0, $iExtended, 1)

EndFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _UninstallList
; Description ...: Returns an array of matching uninstall keys from registry, with an optional filter
; Syntax ........: _UninstallList([$sValueName = ""[, $sFilter = ""[, $sCols = ""[, $iSearchMode = 0[,$ iArch = 3]]]]]])
; Parameters ....: $sValueName       - [optional] Registry value used for the filter.
;                                          Default is all keys ($sFilter do not operates).
;                  $sFilter          - [optional] String to search in $sValueName. Filter is not case sensitive.
;                  $sCols            - [optional] Additional values to retrieve. Use "|" to separate each value.
;                                          Each value adds a column in the returned array
;                  $iSearchMode      - [optional] Search mode. Default is 0.
;                                          0 : Match string from the start.
;                                          1 : Match any substring.
;                                          2 : Exact string match.
;                                          3 : $sFilter is a regular expression
;                  $iArch            - [optional] Registry keys to search in. Default is 3.
;                                          1 : x86 registry keys only
;                                          2 : x64 registry keys only
;                                          3 : both x86 and x64 registry keys
; Return values .: Returns a 2D array of registry keys and values :
;                      $array[0][0] : Number of keys
;                      $array[n][0] : Registry key path
;                      $array[n][1] : Registry subkey
;                      $array[n][2] : Display name
;                      $array[n][3] : Installation date (YYYYMMDD format)
;                      $array[n][4] : 1st additional value specified in $sCols (only if $sCols is set)
;                      $array[n][5] : 2nd additional value specified in $sCols (only if $sCols contains at least 2 entries)
;                      $array[n][x] : Nth additional value ...
; Author ........: jguinch
; ===============================================================================================================================
Func _UninstallList($sValueName = "", $sFilter = "", $sCols = "", $iSearchMode = 0, $iArch = 3)
    Local $sHKLMx86, $sHKLM64, $sHKCU = "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $aKeys[1] = [ $sHKCU ]
    Local $sDisplayName, $sSubKey, $sKeyDate, $sDate, $sValue, $iFound, $n, $aResult[1][4], $iCol
    Local $aCols[1] = [0]

    If NOT IsInt($iArch) OR $iArch < 0 OR $iArch > 3 Then Return SetError(1, 0, 0)
    If NOT IsInt($iSearchMode) OR $iSearchMode < 0 OR $iSearchMode > 3 Then Return SetError(1, 0, 0)

    $sCols = StringRegExpReplace( StringRegExpReplace($sCols, "(?i)(DisplayName|InstallDate)\|?", ""), "\|$", "")
    If $sCols <> "" Then $aCols = StringSplit($sCols, "|")

    If @OSArch = "X86" Then
        $iArch = 1
        $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Else
        If @AutoitX64 Then
            $sHKLMx86 = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        Else
            $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        EndIf
    EndIf

    If BitAND($iArch, 1) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLMx86
    EndIf

    If BitAND($iArch, 2) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLM64
    EndIf


    For $i = 0 To UBound($aKeys) - 1
        $n = 1
        While 1
            $iFound = 1
            $aSubKey = _RegEnumKeyEx($aKeys[$i], $n)
            If @error Then ExitLoop

            $sSubKey = $aSubKey[0]
            $sKeyDate = StringRegExpReplace($aSubKey[1], "^(\d{4})/(\d{2})/(\d{2}).+", "$1$2$3")
            $sDisplayName = RegRead($aKeys[$i] & "\" & $sSubKey, "DisplayName")
            $sDate = RegRead($aKeys[$i] & "\" & $sSubKey, "InstallDate")
            If $sDate = "" Then $sDate = $sKeyDate

            If $sDisplayName <> "" Then
                 If $sValueName <> "" Then
                    $iFound = 0
                    $sValue = RegRead( $aKeys[$i] & "\" & $sSubKey, $sValueName)
                    If ( $iSearchMode = 0 AND StringInStr($sValue, $sFilter) = 1 ) OR _
                       ( $iSearchMode = 1 AND StringInStr($sValue, $sFilter) ) OR _
                       ( $iSearchMode = 2 AND $sValue = $sFilter ) OR _
                       ( $iSearchMode = 3 AND StringRegExp($sValue, "(?i)" & $sFilter) ) Then
                            $iFound = 1
                    EndIf
                EndIf

                If $iFound Then
                    Redim $aResult[ UBound($aResult) + 1][ 4 + $aCols[0] ]
                    $aResult[ UBound($aResult) - 1][0] = $aKeys[$i]
                    $aResult[ UBound($aResult) - 1][1] = $sSubKey
                    $aResult[ UBound($aResult) - 1][2] = $sDisplayName
                    $aResult[ UBound($aResult) - 1][3] = $sDate

                    For $iCol = 1 To $aCols[0]
                        $aResult[ UBound($aResult) - 1][3 + $iCol] = RegRead( $aKeys[$i] & "\" & $sSubKey, $aCols[$iCol])
                    Next
                EndIf
            EndIf

            $n += 1
        WEnd
    Next

    $aResult[0][0] = UBound($aResult) - 1
    Return $aResult
EndFunc




; #FUNCTION# ====================================================================================================================
; Name ..........: _RegEnumKeyEx
; Description ...: Enumerates the subkeys of the specified open registry key. The function retrieves information about one subkey
;                  each time it is called.
; Syntax ........: _RegEnumKeyEx($sKey, $iInstance)
; Parameters ....: $sKey                - The registry key to read.
;                  $iInstance           - The 1-based key instance to retrieve.
; Return values .: Success              - A 1D array :
;                                          $aArray[0] = subkey name
;                                          $aArray[1] = time at which the enumerated subkey was last written
;                  Failure               - Returns 0 and set @eror to non-zero value
; Author ........: jguinch
; ===============================================================================================================================
Func _RegEnumKeyEx($sKey, $iInstance)
    If NOT IsDeclared("KEY_WOW64_32KEY") Then Local Const $KEY_WOW64_32KEY = 0x0200
    If NOT IsDeclared("KEY_WOW64_64KEY") Then Local Const $KEY_WOW64_64KEY = 0x0100
    If NOT IsDeclared("KEY_ENUMERATE_SUB_KEYS") Then Local Const $KEY_ENUMERATE_SUB_KEYS = 0x0008

    If NOT IsDeclared("tagFILETIME") Then Local Const $tagFILETIME = "struct;dword Lo;dword Hi;endstruct"

    Local $iSamDesired = $KEY_ENUMERATE_SUB_KEYS

    Local $iX64Key = 0, $sRootKey, $aResult[2]

    Local $sRoot = StringRegExpReplace($sKey, "\\.+", "")
    Local $sSubkey = StringRegExpReplace($sKey, "^[^\\]+\\", "")

    $sRoot = StringReplace($sRoot, "64", "")
    If @extended Then $iX64Key = 1

    If NOT IsInt($iInstance) OR $iInstance < 1 Then Return SetError(2, 0, 0)

    Switch $sRoot
        Case "HKCR", "HKEY_CLASSES_ROOT"
            $sRootKey = 0x80000000
        Case "HKLM", "HKEY_LOCAL_MACHINE"
            $sRootKey = 0x80000002
        Case "HKCU", "HKEY_CURRENT_USER"
            $sRootKey = 0x80000001
        Case "HKU", "HKEY_USERS"
            $sRootKey = 0x80000003
        Case  "HKCC", "HKEY_CURRENT_CONFIG"
            $sRootKey = 0x80000005
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    If StringRegExp(@OSArch, "64$") Then
        If @AutoItX64 OR $iX64Key Then
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_64KEY)
        Else
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_32KEY)
        EndIf
    EndIf

    Local $aRetOPen = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'handle', $sRootKey, 'wstr', $sSubKey, 'dword', 0, 'dword', $iSamDesired, 'ulong_ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRetOPen[0] Then Return SetError(10, $aRetOPen[0], 0)

    Local $hKey = $aRetOPen[5]

    Local $tFILETIME = DllStructCreate($tagFILETIME)
    Local $lpftLastWriteTime = DllStructGetPtr($tFILETIME)

    Local $aRetEnum = DllCall('Advapi32.dll', 'long', 'RegEnumKeyExW', 'long', $hKey, 'dword', $iInstance - 1, 'wstr', "", 'dword*', 255, 'dword', "", 'ptr', "", 'dword', "", 'ptr', $lpftLastWriteTime)
    If Not IsArray($aRetEnum) OR $aRetEnum[0] <> 0 Then Return SetError( 3, 0, 1)

    Local $tFILETIME2 = _Date_Time_FileTimeToLocalFileTime($lpftLastWriteTime)
    Local $localtime = _Date_Time_FileTimeToStr($tFILETIME2, 1)

    $aResult[0] = $aRetEnum[3]
    $aResult[1] = $localtime

    Return $aResult
EndFunc

 

Edited by jguinch
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Microsoft Silverlight is not installed.
PDFCreator is not installed.
Java.+?\d+ Update \d is installed.
Adobe flash Player is installed. A newer version than '18' is installed.

That's ran on its own. That is exactly the type of information I am looking for with my list of programs. Could I change "console write" to an array or a text file?

PG1 = Adobe flash Player 19 ActiveX 19.0.0.207
PG2 = Adobe Flash Player 19 Plugin  19.0.0.245
PG3 = Adobe Reader XI 11.0.13
PG4 = CCleaner 5.13
PG5 = Defraggler 2.18
PG6 = Firefox 43.0 (x86 en-US)
PG7 = Google Chrome 46
PG8 = HijackThis 2.0.5
PG9 = HitmanPro 3
PG10 = IncrediMail 2.5
PG11 = Java 8 Update 66 8.0.660.18
PG12 = Malwarebytes Anti-Malware version 2.2.0.1024
PG13 = Microsoft Security Essentials
PG14 = Norton Ghost 15
PG15 = Opera 11.60
PG16 = Spybot – Search & Destroy 2.4
PG17 = SpywareBlaster 5.2
PG18 = SUPERAntiSpyware Version 6.0
PG19 = ThreatFire 4.7.0.53
PG20 = Thunderbird 38
PG21 = TinyWall 2.1
PG22 = Trojan Remover 6.9.3
PG23 = Windows Live Essentials 16.4.3528.0331
PG24 = WinPatrol 33.6.2015.18
PG25=  ZoneAlarm Free Firewall 2015

 

Link to comment
Share on other sites

["Microsoft Silverlight", "5", 0], ["PDFCreator", 0, 0], ["Java.+?\d+ Update \d", "8.0.660.18", 3]

What is the second number for please? [0,3]

Can I write Java as

["Java.+\8+ Update \66", "8.0.660.18", 3]

And change version numbers as the programs are updated?

Link to comment
Share on other sites


I've changed it to suit my purpose. This is still rough I have to refine it yet.
The line after else: ---"is not installed" is reduntant. If a program isn't installed I want to ignore it.

Some of the apps are not outputting correctly. I assume this is because of their path?
"Firefox 43.0 (x86 en-US) is not installed. *out of date*" --- It is installed and up to date
"Malwarebytes Anti-Malware is *out of date*" --- It is up to date

local $File = FileOpen("text.txt", 2)



; #EXAMPLE ======================================================================================================================
Local $aApps = [["Adobe flash Player", "20", 0], ["Adobe Reader XI", "11.0.13", 0], ["CCleaner",  "5.13", 0], ["Defraggler", "2.19.982", 0], ["Firefox 43.0 (x86 en-US)", 0, 0], ["Google Chrome", "46", 0], ["HijackThis", "2.0.5", 0], ["HitmanPro", "3", 0], ["IncrediMail", "2.5", 0], ["Java.+\8+ Update \66", "8.0.660.18", 3], ["Malwarebytes Anti-Malware", "version 2.2.0.1024", 0], ["Microsoft Security Essentials", 0, 0], ["Microsoft Silverlight", "5", 0], ["Norton Ghost", "15", 0], ["Opera", "11.60", 0], ["Spybot – Search & Destroy", "2.4", 0], ["SpywareBlaster", "5.2", 0], ["SUPERAntiSpyware", "Version 6.0", 0], ["ThreatFire", "4.7.0.53", 0], ["Thunderbird", "38", 0], ["Windows Live Essentials", "16.4.3528.0331", 0], ["WinPatrol", "33.6.2015.18", 0]]

Local $iIsInstalled, $sRes, $sUTP
For $i = 0 To UBound($aApps) - 1
    $iIsInstalled = _IsInstalled($aApps[$i][0], $aApps[$i][1], $aApps[$i][2])
    If $iIsInstalled Then
        $sRes = " is"
        Switch @extended
            Case -1
                $sUTP = " *out of date*"
            Case 1
                $sUTP = ""
            Case 0
                $sUTP = " up to date!"
        EndSwitch
    Else
        $sRes = " is not installed."
    EndIf
    filewrite($File, $aApps[$i][0] & $sRes & $sUTP & @CRLF)
Next

I fixed Firefox and MBAM.

Edited by dcoggie
Link to comment
Share on other sites

I've sorted all my previous queries out. Now I'm left with 2 problems.
PROBLEM 1:
I would like this line to show the version that is installed on the computer. I've been experimenting with entries in the _IsInstalled function but I keep getting a blank printout.
[$sRes = " is installed."]
PROBLEM 2:
If a program is not installed then I don't want any information about it printed out at all. Altering this entry does not solve the problem:
[Else
        $sRes = " is not installed."]

 

Link to comment
Share on other sites

Problem 1 - You'll have to write a separate function for each program to find the version number and return the value and keep it updated.The way you retrieve the version number will likely change over time as the console output is no longer supported or a control changes its name in a program. 

Problem 2 - You can make a script that checks the installed programs against the ones you want to monitor. Again this will likely change over time. 

You might want to look at a free website that does this kind of thing ninite.com

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Hello computergroove.

Thank you for the suggestions. There has been a mixup. I apologize.

It is my fault for not posting all the information about the script I'm working on. This script is part of a function that uses jguinch's new function _IsInstalled which checks if an application is installed, and also checks the version. The complete script can be found in the first post at the top of this page. Post #21.

Once again, I apologize.

Link to comment
Share on other sites

Can you link directly to the post by jguinch for the _IsInstalled UDF? Im having trouble finding it.

Sure, no problem.

https://www.autoitscript.com/forum/topic/179308-help-using-regenumkey/?do=findComment&comment=1288676

This is my effort to adapt jguinch's script to what I want. It's not very good but it basically is doing what I want it to do.  I have used "ConsoleWrite" in an attempt to solve "Problem 2". Can you use "ConsoleWrite" in a script that is compiled into an exe file?

#include <Misc.au3>
#Include <Date.au3>

local $File = FileOpen("text.txt", 2)


; #EXAMPLE ======================================================================================================================
Local $aApps = [["Adobe flash Player", "20", 0], ["Adobe Reader XI", "11.0.13", 0], ["CCleaner",  "5.13", 0], ["Defraggler", "2.19.982", 0], ["Google Chrome", "46", 0], ["HijackThis", "2.0.5", 0], ["HitmanPro", "3", 0], ["IncrediMail", "2.5", 0], ["Java 8 Update 66", "8.0.660.18", 3], ["Malwarebytes Anti-Malware", "2.2.0.1024", 0], ["Microsoft Security Essentials", 0, 0], ["Microsoft Silverlight", "5", 0], ["Mozilla Firefox", "43", 0], ["Norton Ghost", "15", 0], ["Opera", "11.60", 0], ["Spybot – Search & Destroy", "2.4", 0], ["SpywareBlaster", "5.2", 0], ["SUPERAntiSpyware", "Version 6.0", 0], ["ThreatFire", "4.7.0.53", 0], ["Thunderbird", "38", 0], ["Windows Live Essentials", "16.4.3528.0331", 0], ["WinPatrol", "33.6.2015.18", 0]]

local $sMinVersion
Local $iIsInstalled, $sRes, $sUTP
For $i = 0 To UBound($aApps) - 1
    $iIsInstalled = _IsInstalled($aApps[$i][0], $aApps[$i][1], $aApps[$i][2])
    If $iIsInstalled Then
    $sRes = " is "
        Switch @extended
            Case -1
                $sUTP = " *out of date*"
            Case 1
                $sUTP =  $aApps[$i][1]
            Case 0
                $sUTP =  $aApps[$i][1]
        EndSwitch
        Else
       $sRes = " is not installed"
        EndIf
        If $sRes = " is not installed" then
    ConsoleWrite($aApps[$i][0] & $sRes & $sUTP & @CRLF)
        Else
     FileWrite($File, $aApps[$i][0] & $sRes & $sUTP & @CRLF)
        EndIf
        Next



; #FUNCTION# ====================================================================================================================
; Name ..........: _IsInstalled
; Description ...: Checks if an application is installed on the local computer.
; Syntax ........: _IsInstalled($sAppname[, $sMinVersion = 0[, $iSearchMode = 0]])
; Parameters ....: $sAppname            - Application name or partial name (depending of $iSearchMode value).
;                  $sMinVersion         - [optional] Minimum version to check. Default is 0 (don't check for the version).
;                  $iSearchMode         - [optional] Search mode. Default is 0.
;                                            0 : Match string from the start.
;                                            1 : Match any substring.
;                                            2 : Exact string match.
;                                            3 : $sAppname is a regular expression
; Return values .: Success  - 1
;                  Failure  - 0
; Author ........: jguinch
; Remarks .......: on success, @extended is set to:
;                      0   - The specified version is installed (or no version checked if $sMinVersion^= 0)
;                      1   - A newer version is installed
;                     -1   - An older version is installed
; ===============================================================================================================================
Func _IsInstalled($sAppname, $sMinVersion, $iSearchMode = 0)

   Local $aAppList = _UninstallList("DisplayName", $sAppname, "DisplayVersion", $iSearchMode)
    If Not $aAppList[0][0] Then Return 0
    Local $iExtended = -1

    For $i = 1 To $aAppList[0][0]
        $sAppName = $aAppList[$i][2]
        $sVersion = $aAppList[$i][4]

        If StringRegExp($sAppName, "\d+\h*(\.\d+)+$") Then
            $aAppInfo = StringRegExp($sAppName, "(.+?)\h*(\d+(?:\.\d+)+)$", 1)
            $sAppName = $aAppInfo[0]
            If $sVersion = "" Then $sVersion = $aAppInfo[1]
        EndIf

        If $sMinVersion Then
            $iVersionComp = _VersionCompare($sVersion, $sMinVersion )
            If $iVersionComp = 0 And $iExtended = -1 Then $iExtended = 0
            If $iVersionComp = 1 And $iExtended <= 0 Then $iExtended = 1
        Else
            $iExtended = 0
        EndIf
    Next
    Return SetError(0, $iExtended, 1)

EndFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _UninstallList
; Description ...: Returns an array of matching uninstall keys from registry, with an optional filter
; Syntax ........: _UninstallList([$sValueName = ""[, $sFilter = ""[, $sCols = ""[, $iSearchMode = 0[,$ iArch = 3]]]]]])
; Parameters ....: $sValueName       - [optional] Registry value used for the filter.
;                                          Default is all keys ($sFilter do not operates).
;                  $sFilter          - [optional] String to search in $sValueName. Filter is not case sensitive.
;                  $sCols            - [optional] Additional values to retrieve. Use "|" to separate each value.
;                                          Each value adds a column in the returned array
;                  $iSearchMode      - [optional] Search mode. Default is 0.
;                                          0 : Match string from the start.
;                                          1 : Match any substring.
;                                          2 : Exact string match.
;                                          3 : $sFilter is a regular expression
;                  $iArch            - [optional] Registry keys to search in. Default is 3.
;                                          1 : x86 registry keys only
;                                          2 : x64 registry keys only
;                                          3 : both x86 and x64 registry keys
; Return values .: Returns a 2D array of registry keys and values :
;                      $array[0][0] : Number of keys
;                      $array[n][0] : Registry key path
;                      $array[n][1] : Registry subkey
;                      $array[n][2] : Display name
;                      $array[n][3] : Installation date (YYYYMMDD format)
;                      $array[n][4] : 1st additional value specified in $sCols (only if $sCols is set)
;                      $array[n][5] : 2nd additional value specified in $sCols (only if $sCols contains at least 2 entries)
;                      $array[n][x] : Nth additional value ...
; Author ........: jguinch
; ===============================================================================================================================
Func _UninstallList($sValueName = "", $sFilter = "", $sCols = "", $iSearchMode = 0, $iArch = 3)
    Local $sHKLMx86, $sHKLM64, $sHKCU = "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $aKeys[1] = [ $sHKCU ]
    Local $sDisplayName, $sSubKey, $sKeyDate, $sDate, $sValue, $iFound, $n, $aResult[1][4], $iCol
    Local $aCols[1] = [0]

    If NOT IsInt($iArch) OR $iArch < 0 OR $iArch > 3 Then Return SetError(1, 0, 0)
    If NOT IsInt($iSearchMode) OR $iSearchMode < 0 OR $iSearchMode > 3 Then Return SetError(1, 0, 0)

    $sCols = StringRegExpReplace( StringRegExpReplace($sCols, "(?i)(DisplayName|InstallDate)\|?", ""), "\|$", "")
    If $sCols <> "" Then $aCols = StringSplit($sCols, "|")

    If @OSArch = "X86" Then
        $iArch = 1
        $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Else
        If @AutoitX64 Then
            $sHKLMx86 = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        Else
            $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        EndIf
    EndIf

    If BitAND($iArch, 1) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLMx86
    EndIf

    If BitAND($iArch, 2) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLM64
    EndIf


    For $i = 0 To UBound($aKeys) - 1
        $n = 1
        While 1
            $iFound = 1
            $aSubKey = _RegEnumKeyEx($aKeys[$i], $n)
            If @error Then ExitLoop

            $sSubKey = $aSubKey[0]
            $sKeyDate = StringRegExpReplace($aSubKey[1], "^(\d{4})/(\d{2})/(\d{2}).+", "$1$2$3")
            $sDisplayName = RegRead($aKeys[$i] & "\" & $sSubKey, "DisplayName")
            $sDate = RegRead($aKeys[$i] & "\" & $sSubKey, "InstallDate")
            If $sDate = "" Then $sDate = $sKeyDate

            If $sDisplayName <> "" Then
                 If $sValueName <> "" Then
                    $iFound = 0
                    $sValue = RegRead( $aKeys[$i] & "\" & $sSubKey, $sValueName)
                    If ( $iSearchMode = 0 AND StringInStr($sValue, $sFilter) = 1 ) OR _
                       ( $iSearchMode = 1 AND StringInStr($sValue, $sFilter) ) OR _
                       ( $iSearchMode = 2 AND $sValue = $sFilter ) OR _
                       ( $iSearchMode = 3 AND StringRegExp($sValue, "(?i)" & $sFilter) ) Then
                            $iFound = 1
                    EndIf
                EndIf

                If $iFound Then
                    Redim $aResult[ UBound($aResult) + 1][ 4 + $aCols[0] ]
                    $aResult[ UBound($aResult) - 1][0] = $aKeys[$i]
                    $aResult[ UBound($aResult) - 1][1] = $sSubKey
                    $aResult[ UBound($aResult) - 1][2] = $sDisplayName
                    $aResult[ UBound($aResult) - 1][3] = $sDate

                    For $iCol = 1 To $aCols[0]
                        $aResult[ UBound($aResult) - 1][3 + $iCol] = RegRead( $aKeys[$i] & "\" & $sSubKey, $aCols[$iCol])
                    Next
                EndIf
            EndIf

            $n += 1
        WEnd
    Next

    $aResult[0][0] = UBound($aResult) - 1
    Return $aResult
EndFunc




; #FUNCTION# ====================================================================================================================
; Name ..........: _RegEnumKeyEx
; Description ...: Enumerates the subkeys of the specified open registry key. The function retrieves information about one subkey
;                  each time it is called.
; Syntax ........: _RegEnumKeyEx($sKey, $iInstance)
; Parameters ....: $sKey                - The registry key to read.
;                  $iInstance           - The 1-based key instance to retrieve.
; Return values .: Success              - A 1D array :
;                                          $aArray[0] = subkey name
;                                          $aArray[1] = time at which the enumerated subkey was last written
;                  Failure               - Returns 0 and set @eror to non-zero value
; Author ........: jguinch
; ===============================================================================================================================
Func _RegEnumKeyEx($sKey, $iInstance)
    If NOT IsDeclared("KEY_WOW64_32KEY") Then Local Const $KEY_WOW64_32KEY = 0x0200
    If NOT IsDeclared("KEY_WOW64_64KEY") Then Local Const $KEY_WOW64_64KEY = 0x0100
    If NOT IsDeclared("KEY_ENUMERATE_SUB_KEYS") Then Local Const $KEY_ENUMERATE_SUB_KEYS = 0x0008

    If NOT IsDeclared("tagFILETIME") Then Local Const $tagFILETIME = "struct;dword Lo;dword Hi;endstruct"

    Local $iSamDesired = $KEY_ENUMERATE_SUB_KEYS

    Local $iX64Key = 0, $sRootKey, $aResult[2]

    Local $sRoot = StringRegExpReplace($sKey, "\\.+", "")
    Local $sSubkey = StringRegExpReplace($sKey, "^[^\\]+\\", "")

    $sRoot = StringReplace($sRoot, "64", "")
    If @extended Then $iX64Key = 1

    If NOT IsInt($iInstance) OR $iInstance < 1 Then Return SetError(2, 0, 0)

    Switch $sRoot
        Case "HKCR", "HKEY_CLASSES_ROOT"
            $sRootKey = 0x80000000
        Case "HKLM", "HKEY_LOCAL_MACHINE"
            $sRootKey = 0x80000002
        Case "HKCU", "HKEY_CURRENT_USER"
            $sRootKey = 0x80000001
        Case "HKU", "HKEY_USERS"
            $sRootKey = 0x80000003
        Case  "HKCC", "HKEY_CURRENT_CONFIG"
            $sRootKey = 0x80000005
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    If StringRegExp(@OSArch, "64$") Then
        If @AutoItX64 OR $iX64Key Then
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_64KEY)
        Else
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_32KEY)
        EndIf
    EndIf

    Local $aRetOPen = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'handle', $sRootKey, 'wstr', $sSubKey, 'dword', 0, 'dword', $iSamDesired, 'ulong_ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRetOPen[0] Then Return SetError(10, $aRetOPen[0], 0)

    Local $hKey = $aRetOPen[5]

    Local $tFILETIME = DllStructCreate($tagFILETIME)
    Local $lpftLastWriteTime = DllStructGetPtr($tFILETIME)

    Local $aRetEnum = DllCall('Advapi32.dll', 'long', 'RegEnumKeyExW', 'long', $hKey, 'dword', $iInstance - 1, 'wstr', "", 'dword*', 255, 'dword', "", 'ptr', "", 'dword', "", 'ptr', $lpftLastWriteTime)
    If Not IsArray($aRetEnum) OR $aRetEnum[0] <> 0 Then Return SetError( 3, 0, 1)



 Local $tFILETIME2 = _Date_Time_FileTimeToLocalFileTime($lpftLastWriteTime)
    Local $localtime = _Date_Time_FileTimeToStr($tFILETIME2, 1)

    $aResult[0] = $aRetEnum[3]
    $aResult[1] = $localtime

    Return $aResult
EndFunc

 

Link to comment
Share on other sites


This script is close to what I want.  An example of the output.

Adobe flash Player is installed  and is *out of date*
Adobe Reader XI is installed version 11.0.13
CCleaner is installed version 5.13
Defraggler is installed  and is *out of date*

If possible can I change [ $sRes = " is installed "] to  [$sRes = "DisplayVersion" of the installed app, not $aApps[$i][1]]

I changed ConsoleWrite to a string value. Which is better Console or string?
If $sRes = " is not installed" then
$NoProgram = ($aApps[$i][0] & $sRes & $sUTP & @CRLF)

#include <Misc.au3>
#Include <Date.au3>

local $File = FileOpen("text.txt", 2)


; #EXAMPLE ======================================================================================================================
Local $aApps = [["Adobe flash Player", "20.0.0267", 0], ["Adobe Reader XI", "11.0.13", 0], ["CCleaner",  "5.13", 0], ["Defraggler", "2.19.982", 0], ["Google Chrome", "47.0.2526.106", 0], ["HijackThis", "2.0.5", 0], ["HitmanPro", "3", 0], ["IncrediMail", "2.5", 0], ["Java 8 Update 66", "8.0.660.18", 3], ["Malwarebytes Anti-Malware", "2.2.0.1024", 0], ["Microsoft Security Essentials", 0, 0], ["Microsoft Silverlight", "5", 0], ["Mozilla Firefox", "43.0.3", 0], ["Norton Ghost", "15", 0], ["Opera", "34.0.2036.25", 0], ["Safari", "5.1.7", 0], ["Spybot - Search & Destroy", "2.4", 0], ["SpywareBlaster", "5.4", 0], ["SUPERAntiSpyware", "Version 6.0.1210", 0], ["ThreatFire", "4.7.0.53", 0], ["Thunderbird", "38.5.0", 0], ["Windows Live Essentials", "16.4.3528.0331", 0], ["WinPatrol", "33.6.2015.18", 0]]

local $sMinVersion
Local $iIsInstalled, $sRes, $sUTP
Local $NoProgram
For $i = 0 To UBound($aApps) - 1
    $iIsInstalled = _IsInstalled($aApps[$i][0], $aApps[$i][1], $aApps[$i][2])
    If $iIsInstalled Then
    $sRes = " is installed "
        Switch @extended
            Case -1
                $sUTP = " and is *out of date*"
            Case 1
                $sUTP = "version " & $aApps[$i][1]
            Case 0
                $sUTP = "version " & $aApps[$i][1]
        EndSwitch
        Else
       $sRes = " is not installed"
        EndIf
        If $sRes = " is not installed" then
    $NoProgram = ($aApps[$i][0] & $sRes & $sUTP & @CRLF)
        Else
     FileWrite($File, $aApps[$i][0] & $sRes & $sUTP & @CRLF)
        EndIf
        Next


; #FUNCTION# ====================================================================================================================
; Name ..........: _IsInstalled
; Description ...: Checks if an application is installed on the local computer.
; Syntax ........: _IsInstalled($sAppname[, $sMinVersion = 0[, $iSearchMode = 0]])
; Parameters ....: $sAppname            - Application name or partial name (depending of $iSearchMode value).
;                  $sMinVersion         - [optional] Minimum version to check. Default is 0 (don't check for the version).
;                  $iSearchMode         - [optional] Search mode. Default is 0.
;                                            0 : Match string from the start.
;                                            1 : Match any substring.
;                                            2 : Exact string match.
;                                            3 : $sAppname is a regular expression
; Return values .: Success  - 1
;                  Failure  - 0
; Author ........: jguinch
; Remarks .......: on success, @extended is set to:
;                      0   - The specified version is installed (or no version checked if $sMinVersion^= 0)
;                      1   - A newer version is installed
;                     -1   - An older version is installed
; ===============================================================================================================================
Func _IsInstalled($sAppname, $sMinVersion, $iSearchMode = 0)

   Local $aAppList = _UninstallList("DisplayName", $sAppname, "DisplayVersion", $iSearchMode)
    If Not $aAppList[0][0] Then Return 0
    Local $iExtended = -1

    For $i = 1 To $aAppList[0][0]
        $sAppName = $aAppList[$i][2]
        $sVersion = $aAppList[$i][4]

        If StringRegExp($sAppName, "\d+\h*(\.\d+)+$") Then
            $aAppInfo = StringRegExp($sAppName, "(.+?)\h*(\d+(?:\.\d+)+)$", 1)
            $sAppName = $aAppInfo[0]
            If $sVersion = "" Then $sVersion = $aAppInfo[1]
        EndIf

        If $sMinVersion Then
            $iVersionComp = _VersionCompare($sVersion, $sMinVersion )
            If $iVersionComp = 0 And $iExtended = -1 Then $iExtended = 0
            If $iVersionComp = 1 And $iExtended <= 0 Then $iExtended = 1
        Else
            $iExtended = 0
        EndIf
    Next
    Return SetError(0, $iExtended, 1)

EndFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _UninstallList
; Description ...: Returns an array of matching uninstall keys from registry, with an optional filter
; Syntax ........: _UninstallList([$sValueName = ""[, $sFilter = ""[, $sCols = ""[, $iSearchMode = 0[,$ iArch = 3]]]]]])
; Parameters ....: $sValueName       - [optional] Registry value used for the filter.
;                                          Default is all keys ($sFilter do not operates).
;                  $sFilter          - [optional] String to search in $sValueName. Filter is not case sensitive.
;                  $sCols            - [optional] Additional values to retrieve. Use "|" to separate each value.
;                                          Each value adds a column in the returned array
;                  $iSearchMode      - [optional] Search mode. Default is 0.
;                                          0 : Match string from the start.
;                                          1 : Match any substring.
;                                          2 : Exact string match.
;                                          3 : $sFilter is a regular expression
;                  $iArch            - [optional] Registry keys to search in. Default is 3.
;                                          1 : x86 registry keys only
;                                          2 : x64 registry keys only
;                                          3 : both x86 and x64 registry keys
; Return values .: Returns a 2D array of registry keys and values :
;                      $array[0][0] : Number of keys
;                      $array[n][0] : Registry key path
;                      $array[n][1] : Registry subkey
;                      $array[n][2] : Display name
;                      $array[n][3] : Installation date (YYYYMMDD format)
;                      $array[n][4] : 1st additional value specified in $sCols (only if $sCols is set)
;                      $array[n][5] : 2nd additional value specified in $sCols (only if $sCols contains at least 2 entries)
;                      $array[n][x] : Nth additional value ...
; Author ........: jguinch
; ===============================================================================================================================
Func _UninstallList($sValueName = "", $sFilter = "", $sCols = "", $iSearchMode = 0, $iArch = 3)
    Local $sHKLMx86, $sHKLM64, $sHKCU = "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $aKeys[1] = [ $sHKCU ]
    Local $sDisplayName, $sSubKey, $sKeyDate, $sDate, $sValue, $iFound, $n, $aResult[1][4], $iCol
    Local $aCols[1] = [0]

    If NOT IsInt($iArch) OR $iArch < 0 OR $iArch > 3 Then Return SetError(1, 0, 0)
    If NOT IsInt($iSearchMode) OR $iSearchMode < 0 OR $iSearchMode > 3 Then Return SetError(1, 0, 0)

    $sCols = StringRegExpReplace( StringRegExpReplace($sCols, "(?i)(DisplayName|InstallDate)\|?", ""), "\|$", "")
    If $sCols <> "" Then $aCols = StringSplit($sCols, "|")

    If @OSArch = "X86" Then
        $iArch = 1
        $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Else
        If @AutoitX64 Then
            $sHKLMx86 = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        Else
            $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        EndIf
    EndIf

    If BitAND($iArch, 1) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLMx86
    EndIf

    If BitAND($iArch, 2) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLM64
    EndIf


    For $i = 0 To UBound($aKeys) - 1
        $n = 1
        While 1
            $iFound = 1
            $aSubKey = _RegEnumKeyEx($aKeys[$i], $n)
            If @error Then ExitLoop

            $sSubKey = $aSubKey[0]
            $sKeyDate = StringRegExpReplace($aSubKey[1], "^(\d{4})/(\d{2})/(\d{2}).+", "$1$2$3")
            $sDisplayName = RegRead($aKeys[$i] & "\" & $sSubKey, "DisplayName")
            $sDate = RegRead($aKeys[$i] & "\" & $sSubKey, "InstallDate")
            If $sDate = "" Then $sDate = $sKeyDate

            If $sDisplayName <> "" Then
                 If $sValueName <> "" Then
                    $iFound = 0
                    $sValue = RegRead( $aKeys[$i] & "\" & $sSubKey, $sValueName)
                    If ( $iSearchMode = 0 AND StringInStr($sValue, $sFilter) = 1 ) OR _
                       ( $iSearchMode = 1 AND StringInStr($sValue, $sFilter) ) OR _
                       ( $iSearchMode = 2 AND $sValue = $sFilter ) OR _
                       ( $iSearchMode = 3 AND StringRegExp($sValue, "(?i)" & $sFilter) ) Then
                            $iFound = 1
                    EndIf
                EndIf

                If $iFound Then
                    Redim $aResult[ UBound($aResult) + 1][ 4 + $aCols[0] ]
                    $aResult[ UBound($aResult) - 1][0] = $aKeys[$i]
                    $aResult[ UBound($aResult) - 1][1] = $sSubKey
                    $aResult[ UBound($aResult) - 1][2] = $sDisplayName
                    $aResult[ UBound($aResult) - 1][3] = $sDate

                    For $iCol = 1 To $aCols[0]
                        $aResult[ UBound($aResult) - 1][3 + $iCol] = RegRead( $aKeys[$i] & "\" & $sSubKey, $aCols[$iCol])
                    Next
                EndIf
            EndIf

            $n += 1
        WEnd
    Next

    $aResult[0][0] = UBound($aResult) - 1
    Return $aResult
EndFunc




; #FUNCTION# ====================================================================================================================
; Name ..........: _RegEnumKeyEx
; Description ...: Enumerates the subkeys of the specified open registry key. The function retrieves information about one subkey
;                  each time it is called.
; Syntax ........: _RegEnumKeyEx($sKey, $iInstance)
; Parameters ....: $sKey                - The registry key to read.
;                  $iInstance           - The 1-based key instance to retrieve.
; Return values .: Success              - A 1D array :
;                                          $aArray[0] = subkey name
;                                          $aArray[1] = time at which the enumerated subkey was last written
;                  Failure               - Returns 0 and set @eror to non-zero value
; Author ........: jguinch
; ===============================================================================================================================
Func _RegEnumKeyEx($sKey, $iInstance)
    If NOT IsDeclared("KEY_WOW64_32KEY") Then Local Const $KEY_WOW64_32KEY = 0x0200
    If NOT IsDeclared("KEY_WOW64_64KEY") Then Local Const $KEY_WOW64_64KEY = 0x0100
    If NOT IsDeclared("KEY_ENUMERATE_SUB_KEYS") Then Local Const $KEY_ENUMERATE_SUB_KEYS = 0x0008

    If NOT IsDeclared("tagFILETIME") Then Local Const $tagFILETIME = "struct;dword Lo;dword Hi;endstruct"

    Local $iSamDesired = $KEY_ENUMERATE_SUB_KEYS

    Local $iX64Key = 0, $sRootKey, $aResult[2]

    Local $sRoot = StringRegExpReplace($sKey, "\\.+", "")
    Local $sSubkey = StringRegExpReplace($sKey, "^[^\\]+\\", "")

    $sRoot = StringReplace($sRoot, "64", "")
    If @extended Then $iX64Key = 1

    If NOT IsInt($iInstance) OR $iInstance < 1 Then Return SetError(2, 0, 0)

    Switch $sRoot
        Case "HKCR", "HKEY_CLASSES_ROOT"
            $sRootKey = 0x80000000
        Case "HKLM", "HKEY_LOCAL_MACHINE"
            $sRootKey = 0x80000002
        Case "HKCU", "HKEY_CURRENT_USER"
            $sRootKey = 0x80000001
        Case "HKU", "HKEY_USERS"
            $sRootKey = 0x80000003
        Case  "HKCC", "HKEY_CURRENT_CONFIG"
            $sRootKey = 0x80000005
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    If StringRegExp(@OSArch, "64$") Then
        If @AutoItX64 OR $iX64Key Then
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_64KEY)
        Else
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_32KEY)
        EndIf
    EndIf

    Local $aRetOPen = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'handle', $sRootKey, 'wstr', $sSubKey, 'dword', 0, 'dword', $iSamDesired, 'ulong_ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRetOPen[0] Then Return SetError(10, $aRetOPen[0], 0)

    Local $hKey = $aRetOPen[5]

    Local $tFILETIME = DllStructCreate($tagFILETIME)
    Local $lpftLastWriteTime = DllStructGetPtr($tFILETIME)

    Local $aRetEnum = DllCall('Advapi32.dll', 'long', 'RegEnumKeyExW', 'long', $hKey, 'dword', $iInstance - 1, 'wstr', "", 'dword*', 255, 'dword', "", 'ptr', "", 'dword', "", 'ptr', $lpftLastWriteTime)
    If Not IsArray($aRetEnum) OR $aRetEnum[0] <> 0 Then Return SetError( 3, 0, 1)



 Local $tFILETIME2 = _Date_Time_FileTimeToLocalFileTime($lpftLastWriteTime)
    Local $localtime = _Date_Time_FileTimeToStr($tFILETIME2, 1)

    $aResult[0] = $aRetEnum[3]
    $aResult[1] = $localtime

    Return $aResult
EndFunc

 

Link to comment
Share on other sites

It depends on what you want to do with the info. Where would the console info go if you compiled the exe? I'm imagining a GUI that shows this data on a line by line interface that allows the user to update all or individual items unless you are just trying to inform the user. Are you remote administering or is this for the end user to figure out or something else? I tried to run your script and I got no output in the console. 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

I am attempting to compare 2 text files. I want 3 outcomes.
1. a match when the names and the numbers are the same
2. a match when the names are the same but the numbers are different
3. if no match at all end

sample from scan.txt:
Adobe Flash Player 19 ActiveX-19.0.0.207
Adobe Flash Player 20 NPAPI-20.0.0.267
CCleaner-5.13

sample from text.txt:
Adobe flash Player 19 ActiveX - 19
Adobe flash Player 20 NPAPI-20
CCleaner-5.13


with both of these scripts I am not getting any matches at all.

#include <Array.au3>
#include <file.au3>

Local $array1
Local $array2

_FileReadToArray("scan.txt", $array1)
_FileReadToArray("text.txt", $array2)

For $X = 1 to $array1[0]
    If $X <= $array2[0] Then
        If $array1[$X] = $array2[$X] Then
            $array1[$X] &= " has a match."
        Else
            $array1[$X] &= " does NOT have a match."
        EndIf
    Else
        ExitLoop
    EndIf
Next

_FileWriteFromArray("scan.txt",$array1, 1)

 

$fileOpen = FileOpen("scan.txt")
$fileRead = FileRead($fileOpen)
if $fileread <> "CCleaner 5.13" then
if $fileread = "CCleaner 5.13" Then
    msgbox(0, "", "right")
    else
msgbox(0, "", "wrong")
Exit
    EndIf
    EndIf
FileClose($fileOpen)

 

Link to comment
Share on other sites

I've got this script to work. Now, can anyone help me. I want to run a second loop that will match all the out of date programs.
Example: up to date CCleaner is 5.13 - The version installed on the computer is 4. At the moment this is not a match.

#include <Array.au3>
#include <file.au3>

Local $array1
Local $array2

_FileReadToArray("scan.txt", $array1)
_FileReadToArray("text.txt", $array2)

For $X = 1 to $array1[0]
    If $X <= $array2[0] Then
        If $array1[$X] = $array2[$X] Then
            $array1[$X] &= " has a match."
        Else
            $array1[$X] &= " does NOT have a match."
        EndIf
    Else
        ExitLoop
    EndIf
Next

_FileWriteFromArray("scan.txt",$array1, 1)

 

Link to comment
Share on other sites

Can you try the following code ?

#include <Misc.au3>
#Include <Date.au3>

Local $sOutputFile = @ScriptDir & "\OutOfDatePrograms.txt"
Local $aApps = [["Microsoft Silverlight", "5", 0], ["Java.+?\d+ Update \d", "9.0.510.22", 3], ["Adobe flash Player", "18", 0]]
Local $aOFDPrograms
Local $hOut = FileOpen($sOutputFile, 1)
Local $hOut = FileOpen($sOutputFile, 1)

For $i = 0 To UBound($aApps) - 1
    $aOFDPrograms = _GetOutOfDatePrograms($aApps[$i][0], $aApps[$i][1], $aApps[$i][2])
    If Not @error Then
        FileWriteLine($hOut, "Out of date programs for " & $aApps[$i][0] & " : ")
        For $n = 0 To UBound($aOFDPrograms) - 1
            FileWriteLine($hOut, " - " & $aOFDPrograms[$n][0] & " (version " & $aOFDPrograms[$n][0] & ")")
        Next
    EndIf
Next


Func _GetOutOfDatePrograms($sAppname, $sMinVersion, $iSearchMode = 0)
    Local $aAppList = _UninstallList("DisplayName", $sAppname, "DisplayVersion", $iSearchMode)
    If Not $aAppList[0][0] Then Return 0
    Local $iExtended = -1
    Local $aRet[ $aAppList[0][0]  ][2], $n = 0

    For $i = 1 To $aAppList[0][0]
        $sAppName = $aAppList[$i][2]
        $sVersion = $aAppList[$i][4]

        If StringRegExp($sAppName, "\d+\h*(\.\d+)+$") Then
            $aAppInfo = StringRegExp($sAppName, "(.+?)\h*(\d+(?:\.\d+)+)$", 1)
            $sAppName = $aAppInfo[0]
            If $sVersion = "" Then $sVersion = $aAppInfo[1]
        EndIf

        $iVersionComp = _VersionCompare($sVersion, $sMinVersion )
        If $iVersionComp = -1 Then
            $aRet[$n][0] = $sAppName
            $aRet[$n][1] = $sVersion
            $n += 1
        EndIf
    Next

    If $n = 0 Then Return SetError(1, 0, 0)
    ReDim $aRet[$n][2]
    Return $aRet

EndFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _UninstallList
; Description ...: Returns an array of matching uninstall keys from registry, with an optional filter
; Syntax ........: _UninstallList([$sValueName = ""[, $sFilter = ""[, $sCols = ""[, $iSearchMode = 0[,$ iArch = 3]]]]]])
; Parameters ....: $sValueName       - [optional] Registry value used for the filter.
;                                          Default is all keys ($sFilter do not operates).
;                  $sFilter          - [optional] String to search in $sValueName. Filter is not case sensitive.
;                  $sCols            - [optional] Additional values to retrieve. Use "|" to separate each value.
;                                          Each value adds a column in the returned array
;                  $iSearchMode      - [optional] Search mode. Default is 0.
;                                          0 : Match string from the start.
;                                          1 : Match any substring.
;                                          2 : Exact string match.
;                                          3 : $sFilter is a regular expression
;                  $iArch            - [optional] Registry keys to search in. Default is 3.
;                                          1 : x86 registry keys only
;                                          2 : x64 registry keys only
;                                          3 : both x86 and x64 registry keys
; Return values .: Returns a 2D array of registry keys and values :
;                      $array[0][0] : Number of keys
;                      $array[n][0] : Registry key path
;                      $array[n][1] : Registry subkey
;                      $array[n][2] : Display name
;                      $array[n][3] : Installation date (YYYYMMDD format)
;                      $array[n][4] : 1st additional value specified in $sCols (only if $sCols is set)
;                      $array[n][5] : 2nd additional value specified in $sCols (only if $sCols contains at least 2 entries)
;                      $array[n][x] : Nth additional value ...
; Author ........: jguinch
; ===============================================================================================================================
Func _UninstallList($sValueName = "", $sFilter = "", $sCols = "", $iSearchMode = 0, $iArch = 3)
    Local $sHKLMx86, $sHKLM64, $sHKCU = "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $aKeys[1] = [ $sHKCU ]
    Local $sDisplayName, $sSubKey, $sKeyDate, $sDate, $sValue, $iFound, $n, $aResult[1][4], $iCol
    Local $aCols[1] = [0]

    If NOT IsInt($iArch) OR $iArch < 0 OR $iArch > 3 Then Return SetError(1, 0, 0)
    If NOT IsInt($iSearchMode) OR $iSearchMode < 0 OR $iSearchMode > 3 Then Return SetError(1, 0, 0)

    $sCols = StringRegExpReplace( StringRegExpReplace($sCols, "(?i)(DisplayName|InstallDate)\|?", ""), "\|$", "")
    If $sCols <> "" Then $aCols = StringSplit($sCols, "|")

    If @OSArch = "X86" Then
        $iArch = 1
        $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Else
        If @AutoitX64 Then
            $sHKLMx86 = "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        Else
            $sHKLMx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            $sHKLM64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        EndIf
    EndIf

    If BitAND($iArch, 1) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLMx86
    EndIf

    If BitAND($iArch, 2) Then
        Redim $aKeys[ UBound($aKeys) + 1]
        $aKeys [ UBound($aKeys) - 1] = $sHKLM64
    EndIf


    For $i = 0 To UBound($aKeys) - 1
        $n = 1
        While 1
            $iFound = 1
            $aSubKey = _RegEnumKeyEx($aKeys[$i], $n)
            If @error Then ExitLoop

            $sSubKey = $aSubKey[0]
            $sKeyDate = StringRegExpReplace($aSubKey[1], "^(\d{4})/(\d{2})/(\d{2}).+", "$1$2$3")
            $sDisplayName = RegRead($aKeys[$i] & "\" & $sSubKey, "DisplayName")
            $sDate = RegRead($aKeys[$i] & "\" & $sSubKey, "InstallDate")
            If $sDate = "" Then $sDate = $sKeyDate

            If $sDisplayName <> "" Then
                 If $sValueName <> "" Then
                    $iFound = 0
                    $sValue = RegRead( $aKeys[$i] & "\" & $sSubKey, $sValueName)
                    If ( $iSearchMode = 0 AND StringInStr($sValue, $sFilter) = 1 ) OR _
                       ( $iSearchMode = 1 AND StringInStr($sValue, $sFilter) ) OR _
                       ( $iSearchMode = 2 AND $sValue = $sFilter ) OR _
                       ( $iSearchMode = 3 AND StringRegExp($sValue, "(?i)" & $sFilter) ) Then
                            $iFound = 1
                    EndIf
                EndIf

                If $iFound Then
                    Redim $aResult[ UBound($aResult) + 1][ 4 + $aCols[0] ]
                    $aResult[ UBound($aResult) - 1][0] = $aKeys[$i]
                    $aResult[ UBound($aResult) - 1][1] = $sSubKey
                    $aResult[ UBound($aResult) - 1][2] = $sDisplayName
                    $aResult[ UBound($aResult) - 1][3] = $sDate

                    For $iCol = 1 To $aCols[0]
                        $aResult[ UBound($aResult) - 1][3 + $iCol] = RegRead( $aKeys[$i] & "\" & $sSubKey, $aCols[$iCol])
                    Next
                EndIf
            EndIf

            $n += 1
        WEnd
    Next

    $aResult[0][0] = UBound($aResult) - 1
    Return $aResult
EndFunc




; #FUNCTION# ====================================================================================================================
; Name ..........: _RegEnumKeyEx
; Description ...: Enumerates the subkeys of the specified open registry key. The function retrieves information about one subkey
;                  each time it is called.
; Syntax ........: _RegEnumKeyEx($sKey, $iInstance)
; Parameters ....: $sKey                - The registry key to read.
;                  $iInstance           - The 1-based key instance to retrieve.
; Return values .: Success              - A 1D array :
;                                          $aArray[0] = subkey name
;                                          $aArray[1] = time at which the enumerated subkey was last written
;                  Failure               - Returns 0 and set @eror to non-zero value
; Author ........: jguinch
; ===============================================================================================================================
Func _RegEnumKeyEx($sKey, $iInstance)
    If NOT IsDeclared("KEY_WOW64_32KEY") Then Local Const $KEY_WOW64_32KEY = 0x0200
    If NOT IsDeclared("KEY_WOW64_64KEY") Then Local Const $KEY_WOW64_64KEY = 0x0100
    If NOT IsDeclared("KEY_ENUMERATE_SUB_KEYS") Then Local Const $KEY_ENUMERATE_SUB_KEYS = 0x0008

    If NOT IsDeclared("tagFILETIME") Then Local Const $tagFILETIME = "struct;dword Lo;dword Hi;endstruct"

    Local $iSamDesired = $KEY_ENUMERATE_SUB_KEYS

    Local $iX64Key = 0, $sRootKey, $aResult[2]

    Local $sRoot = StringRegExpReplace($sKey, "\\.+", "")
    Local $sSubkey = StringRegExpReplace($sKey, "^[^\\]+\\", "")

    $sRoot = StringReplace($sRoot, "64", "")
    If @extended Then $iX64Key = 1

    If NOT IsInt($iInstance) OR $iInstance < 1 Then Return SetError(2, 0, 0)

    Switch $sRoot
        Case "HKCR", "HKEY_CLASSES_ROOT"
            $sRootKey = 0x80000000
        Case "HKLM", "HKEY_LOCAL_MACHINE"
            $sRootKey = 0x80000002
        Case "HKCU", "HKEY_CURRENT_USER"
            $sRootKey = 0x80000001
        Case "HKU", "HKEY_USERS"
            $sRootKey = 0x80000003
        Case  "HKCC", "HKEY_CURRENT_CONFIG"
            $sRootKey = 0x80000005
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    If StringRegExp(@OSArch, "64$") Then
        If @AutoItX64 OR $iX64Key Then
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_64KEY)
        Else
            $iSamDesired = BitOR($iSamDesired, $KEY_WOW64_32KEY)
        EndIf
    EndIf

    Local $aRetOPen = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'handle', $sRootKey, 'wstr', $sSubKey, 'dword', 0, 'dword', $iSamDesired, 'ulong_ptr*', 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRetOPen[0] Then Return SetError(10, $aRetOPen[0], 0)

    Local $hKey = $aRetOPen[5]

    Local $tFILETIME = DllStructCreate($tagFILETIME)
    Local $lpftLastWriteTime = DllStructGetPtr($tFILETIME)

    Local $aRetEnum = DllCall('Advapi32.dll', 'long', 'RegEnumKeyExW', 'long', $hKey, 'dword', $iInstance - 1, 'wstr', "", 'dword*', 255, 'dword', "", 'ptr', "", 'dword', "", 'ptr', $lpftLastWriteTime)
    If Not IsArray($aRetEnum) OR $aRetEnum[0] <> 0 Then Return SetError( 3, 0, 1)

    Local $tFILETIME2 = _Date_Time_FileTimeToLocalFileTime($lpftLastWriteTime)
    Local $localtime = _Date_Time_FileTimeToStr($tFILETIME2, 1)

    $aResult[0] = $aRetEnum[3]
    $aResult[1] = $localtime

    Return $aResult
EndFunc

 

Edited by jguinch
Link to comment
Share on other sites

This is what I got, hope it is what you expected.

Out of date programs for Java.+?\d+ Update \d :
 - Java 7 Update 80 (version Java 7 Update 80)
 - Java™ 6 Update 45 (version Java™ 6 Update 45)
 - Java 8 Update 40 (version Java 8 Update 40)
 - Java 8 Update 66 (version Java 8 Update 66)
 

Is missing the version Java 5 Update 22.

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...