Jump to content

Possible to filter an array? (SOLVED)


Recommended Posts

Hello people

I have found an example of retrieving information from registry and putting it into an array, been reading the wiki on arrays and I'm still a bit puzzled.

Is there a method to filter out certain information. i would like to filter out M$ security patches and hotfixes. [security Update for Windows XP], [update for Microsoft windows], [hotfix for windows xp], [critical update]

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



$random123 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers\Direct3D HAL'
$pcname = InputBox("", "input target machine name" & @CR & "e.g. archimedes", "", " ")
$ret = _SoftwareInfo()
_ArrayDisplay($ret, '')

Func _SoftwareInfo($s_RemoteComputer = $pcname)
    Local $Count = 1

    If $s_RemoteComputer <> '' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
    Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey ($regkey, $Count)
        If @error <> 0 then ExitLoop
        $line = RegRead ($regkey & '\' & $key, 'Displayname')
        $line = StringReplace ($line, ' (remove only)', '')

        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1]
            ReDim $avArray[UBound($avArray) + 1]
            $avArray[UBound($avArray) - 1] = $line
        EndIf
        $Count = $Count + 1
    WEnd

    If Not IsDeclared('avArray') Or Not IsArray($avArray) Then
        Return(SetError(1, 0, ''))
    Else
        $avArray[0] = UBound($avArray) - 1
        Return(SetError(0,0, $avArray))
    EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
EndFunc

As mentioned i found this example, but will try and come up with my own. but i generally only learn from working examples.

any assistance would be great thanks.

ftc

Edited by failedtocompile
Link to comment
Share on other sites

Do something like the following. Add stringinstr lines for any thing else you want to filter out.

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



$random123 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers\Direct3D HAL'
$pcname = InputBox("", "input target machine name" & @CR & "e.g. archimedes", "", " ")
$ret = _SoftwareInfo()
_ArrayDisplay($ret, '')

Func _SoftwareInfo($s_RemoteComputer = $pcname)
    Local $Count = 1

    If $s_RemoteComputer <> '' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
    Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        $line = RegRead($regkey & '\' & $key, 'Displayname')
        $line = StringReplace($line, ' (remove only)', '')
        If StringInStr($line, "[Security Update for Windows XP]") Then ContinueLoop
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1]
            ReDim $avArray[UBound($avArray) + 1]
            $avArray[UBound($avArray) - 1] = $line
        EndIf
        $Count = $Count + 1
    WEnd

    If Not IsDeclared('avArray') Or Not IsArray($avArray) Then
        Return (SetError(1, 0, ''))
    Else
        $avArray[0] = UBound($avArray) - 1
        Return (SetError(0, 0, $avArray))
    EndIf

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>_SoftwareInfo
Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Do something like the following. Add stringinstr lines for any thing else you want to filter out.

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>



$random123 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers\Direct3D HAL'
$pcname = InputBox("", "input target machine name" & @CR & "e.g. archimedes", "", " ")
$ret = _SoftwareInfo()
_ArrayDisplay($ret, '')

Func _SoftwareInfo($s_RemoteComputer = $pcname)
    Local $Count = 1

    If $s_RemoteComputer <> '' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
    Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        $line = RegRead($regkey & '\' & $key, 'Displayname')
        $line = StringReplace($line, ' (remove only)', '')
        If StringInStr($line, "[Security Update for Windows XP]") Then ContinueLoop
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1]
            ReDim $avArray[UBound($avArray) + 1]
            $avArray[UBound($avArray) - 1] = $line
        EndIf
        $Count = $Count + 1
    WEnd

    If Not IsDeclared('avArray') Or Not IsArray($avArray) Then
        Return (SetError(1, 0, ''))
    Else
        $avArray[0] = UBound($avArray) - 1
        Return (SetError(0, 0, $avArray))
    EndIf

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch
    WEnd
EndFunc   ;==>_SoftwareInfo

Hi P5ych0Gigabyte

thanks for the reply but it didn't have the desired affect.

$line = StringReplace($line, 'Security Update for Windows XP', '')

If StringInStr($line, "[security Update for Windows XP]") Then ContinueLoop

still displays the the entry in the list it just removes 'Security Update for Windows XP' but leaves the rest of the string. i.e. KB98756

I'm wanting to remove the entire entry so it does not populate the list at all.

To be honest I have not used StringReplace or StringInStr before so kind of new to that area also.

thanks

ftc

edited: have been reviewing _arrayDelete() but not sure how to delete multiple elements that have the Words Security update, hotfix.

Edited by failedtocompile
Link to comment
Share on other sites

Something like this?

#include <Array.au3>
#include <GUIConstantsEx.au3>

$random123 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers\Direct3D HAL'
$pcname = InputBox(@ComputerName, "input target machine name" & @CR & "e.g. archimedes", @ComputerName, " ")
$ret = _SoftwareInfo()
ConsoleWrite(_ArrayToString($ret, '|', 1) & @CRLF)
;~ $re = StringRegExpReplace(_ArrayToString($ret, '|', 1), '(?<=\|)[^\|]+KB\d{6}[)]*\|', '')
$re = StringRegExpReplace(_ArrayToString($ret, '|', 1), '(?<=\|)[^\|]+KB\d{6}[\w-\)]*\|', '')
;~ ConsoleWrite($re & @CRLF)
$re = StringSplit($re, '|', 2)
_ArrayDisplay($re, '')

Func _SoftwareInfo($s_RemoteComputer = $pcname)
    Local $Count = 1

    If $s_RemoteComputer <> '' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
    Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        $line = RegRead($regkey & '\' & $key, 'Displayname')
        $line = StringReplace($line, ' (remove only)', '')
        If StringInStr($line, "[Security Update for Windows XP]") Then ContinueLoop
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1]
            ReDim $avArray[UBound($avArray) + 1]
            $avArray[UBound($avArray) - 1] = $line
        EndIf
        $Count += 1
    WEnd

    If Not IsDeclared('avArray') Or Not IsArray($avArray) Then
        Return (SetError(1, 0, ''))
    Else
        $avArray[0] = UBound($avArray) - 1
        Return (SetError(0, 0, $avArray))
    EndIf

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch
    WEnd
EndFunc ;==>_SoftwareInfo

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Something like this?

#include <Array.au3>
#include <GUIConstantsEx.au3>

$random123 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers\Direct3D HAL'
$pcname = InputBox(@ComputerName, "input target machine name" & @CR & "e.g. archimedes", @ComputerName, " ")
$ret = _SoftwareInfo()
ConsoleWrite(_ArrayToString($ret, '|', 1) & @CRLF)
;~ $re = StringRegExpReplace(_ArrayToString($ret, '|', 1), '(?<=\|)[^\|]+KB\d{6}[)]*\|', '')
$re = StringRegExpReplace(_ArrayToString($ret, '|', 1), '(?<=\|)[^\|]+KB\d{6}[\w-\)]*\|', '')
;~ ConsoleWrite($re & @CRLF)
$re = StringSplit($re, '|', 2)
_ArrayDisplay($re, '')

Func _SoftwareInfo($s_RemoteComputer = $pcname)
    Local $Count = 1

    If $s_RemoteComputer <> '' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\'
    Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

    While 1
        $key = RegEnumKey($regkey, $Count)
        If @error <> 0 Then ExitLoop
        $line = RegRead($regkey & '\' & $key, 'Displayname')
        $line = StringReplace($line, ' (remove only)', '')
        If StringInStr($line, "[Security Update for Windows XP]") Then ContinueLoop
        If $line <> '' Then
            If Not IsDeclared('avArray') Then Dim $avArray[1]
            ReDim $avArray[UBound($avArray) + 1]
            $avArray[UBound($avArray) - 1] = $line
        EndIf
        $Count += 1
    WEnd

    If Not IsDeclared('avArray') Or Not IsArray($avArray) Then
        Return (SetError(1, 0, ''))
    Else
        $avArray[0] = UBound($avArray) - 1
        Return (SetError(0, 0, $avArray))
    EndIf

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch
    WEnd
EndFunc ;==>_SoftwareInfo

Mega

@Xenobiologist

That is some awesome code and of which has generated the desired effect. Thanks you so much, was thinking i would not get a reply. so was going for another approach. outputting to a text file and using stringReplace, this method is allot better

Where did you locate the information to be able to filter data like that? is there some good documentation (apart from wiki) which explains this as in a example?

anyway Have a great week and thanks again

ftc

Link to comment
Share on other sites

No problem! :)

No wiki, just 3 min of having a look at what regex pattern could do the trick.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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