Sign in to follow this  
Followers 0
au3scr

Need help with addig items to an existing list and then ...

20 posts in this topic

#1 ·  Posted (edited)

Hello, I made scirpt using listview and I have there filter function, that filters list by keyword and show all function which makes all the list visible again. but when I type nothing in filter input box to restore old list then I get some strange new blank elements .

How I could write that _ShowAll() so it wont create blank elements anymore?

read my second post in this topic too :)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <array.au3>

Global $aLVItems

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1024, 800, 150, 85, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$input = GUICtrlCreateInput("", 125, 1, 125, 20)
$filterButton = GUICtrlCreateButton("Filter", 250, 1)
$ListView1 = GUICtrlCreateListView("Program Name|Program State|Program Descripton|Uninstall", 8, 72, 1009, 609, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_TRACKSELECT, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~ ;$item1 = GUICtrlCreateListViewItem("Solid Edge|Not Installed|Solid Edge is a 3D CAD parametric feature solid modeling software.", $ListView1)
;~ ;$item2 = GUICtrlCreateListViewItem("AutoIt|Installed|AutoIt (pronounced aw-tow-it)[1] is a freeware automation language for Microsoft Windows.", $ListView1)
genitems()
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($ListView1, 2, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton("Get program name", 1, 1, 120, 20)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            _GetProgramName()
        Case $filterButton
            _FilterItem(GUICtrlRead($input))
    EndSwitch
WEnd


Func _GetProgramName()
    $sel = _GUICtrlListView_GetSelectedIndices($ListView1, True)
    If $sel[0] = 0 Then Return; exit if none is selected
    $sName = _GUICtrlListView_GetItemText($ListView1, $sel[1], 0);Get 0th column text
    MsgBox(0, "", $sName, -1, $Form1)
EndFunc   ;==>_GetProgramName

Func genitems()

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $c = 1
    Do
        $c += 1
        RegEnumKey($Key, $c)
    Until @error
    $answer = ""
    
    Dim $aLVItems[$c][2]
    $aLVItems[0][0] = $c
    
    For $i = 1 To $c
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
;~ ;  $answer = $answer & @CRLF & "KeyName=" & @CRLF & $var & "Program name="& $var2 & @CRLF  &"Uninstall command=" & $var3 & @CRLF & "Quiet uninstall=" &$var4
;~ ;    ShellExecute($var3)
        If Not $var2 = "" Then
            $ui = "Yes"
            If $var3 = "" Then
                $ui = "No"
            EndIf
            
            $aLVItems[$i][1] = $var2 & "|installed | program or software probably virus or keylogger |" & $ui
            $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
        EndIf
    Next
EndFunc   ;==>genitems
;copied from
Func _FilterItem($sText)
    If ($sText = "") Then _ShowAll()
    Local $strNew = ''
    For $i = 1 To $aLVItems[0][0]
        If StringInStr(_GUICtrlListView_GetItemText($ListView1, $i-1), $sText) Then $strNew &= '$aLVItems['&$i&'][0] = GUICtrlCreateListViewItem($aLVItems['&$i&'][1], $ListView1)' & @LF
    Next
    If $strNew = '' Then Return
    _GUICtrlListView_DeleteAllItems($ListView1)
    Local $aExecute = StringSplit($strNew, @LF)
    For $i = 1 To UBound($aExecute) -1
        Execute($aExecute[$i])
    Next
EndFunc   ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i
   
    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
   
    For $i = 1 To $aLVItems[0][0]-1
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
EndFunc   ;==>_ShowAll

Thank you for everything

Edited by au3scr

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I found new interesting thing.

if edit show all function from (old)

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i
   
    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
   
    For $i = 1 To $aLVItems[0][0]-1
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
EndFunc   ;==>_ShowAll

Then I get all list elements back with out empty elements, but then filtering dont work correctly anymore, how I could fix it?

With dont work correctly I meant thatWhen I filter, I wont get all elements in filtered listview If I type adobe for filtering, I got normally 5 items but with that new function I get about 3 elements.

Also Noticed that if I filter adobe 1-st time i get 3 elements + 1 wrong element + 1-st element is empty.

Then I have to enter nothing in inputbox to make all items again visible.

And then I have to ReEnter adobe in filter input box and then I got all 5 right items.

Edited by au3scr

Share this post


Link to post
Share on other sites

Sorry for bump, I am still looking for help :)


Share this post


Link to post
Share on other sites

@au3scr

Maybe...

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
    Local $i

    For $i = 1 To $aLVItems[0][0] - 1
        If $aLVItems[$i][1] <> '' Then
            $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
        EndIf
    Next
EndFunc   ;==>_ShowAll

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you @FireFox for that quick and working response.

But How to fix that thing?

I normally see 5 Adobe items (highlighted with red line)

but if I enter "adobe" in filter box I see only 2 elements:

5elements

Posted Image

2elements + other unwanted stuff.

Posted Image

Edited by au3scr

Share this post


Link to post
Share on other sites

@au3scr

your filter isnt working at all, for example if I enter Canon I will have AutoIt or Adobe...

I will try to fix it

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@au3scr

found the bug... I've done search of only one thing in the list and the result is the list under searched item... I think its a problem of counting :)

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

your filter isnt working at all,for example if I enter Canon I will have AutoIt or Adobe...

I will try to fix it

@FireFox Try same thing on original script (from1-st post) with out editing, there filter works better (at last I think it works) but restore items don't work then.

with your function, Restore items works perfectly but filter dont work :)

In original unmodified script you must enter in box:

1) "your keyword"

2) ""

3) "your keyword" ( after buggy showing all enter same keyword again and then you see that filter works)

And you should see result like this

Posted Image


Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Your filter didn't work correctly for me, I think this does.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <array.au3>

Global $aLVItems

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1024, 800, 150, 85, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$input = GUICtrlCreateInput("", 125, 1, 125, 20)
$filterButton = GUICtrlCreateButton("Filter", 250, 1)
$ListView1 = GUICtrlCreateListView("Program Name|Program State|Program Descripton|Uninstall", 8, 72, 1009, 609, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_TRACKSELECT, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~;$item1 = GUICtrlCreateListViewItem("Solid Edge|Not Installed|Solid Edge is a 3D CAD parametric feature solid modeling software.", $ListView1)
;~;$item2 = GUICtrlCreateListViewItem("AutoIt|Installed|AutoIt (pronounced aw-tow-it)[1] is a freeware automation language for Microsoft Windows.", $ListView1)
genitems()
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($ListView1, 2, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton("Get program name", 1, 1, 120, 20)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            _GetProgramName()
        Case $filterButton
            _FilterItem(GUICtrlRead($input))
    EndSwitch
WEnd


Func _GetProgramName()
    $sel = _GUICtrlListView_GetSelectedIndices($ListView1, True)
    If $sel[0] = 0 Then Return; exit if none is selected
    $sName = _GUICtrlListView_GetItemText($ListView1, $sel[1], 0);Get 0th column text
    MsgBox(0, "", $sName, -1, $Form1)
EndFunc ;==>_GetProgramName

Func genitems()

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $c = 1
    Do
        $c += 1
        RegEnumKey($Key, $c)
    Until @error
    $answer = ""
    
    Dim $aLVItems[$c][2]
    $aLVItems[0][0] = $c
    
    For $i = 1 To $c
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
;~;  $answer = $answer & @CRLF & "KeyName=" & @CRLF & $var & "Program name="& $var2 & @CRLF  &"Uninstall command=" & $var3 & @CRLF & "Quiet uninstall=" &$var4
;~; ShellExecute($var3)
        If Not $var2 = "" Then
            $ui = "Yes"
            If $var3 = "" Then
                $ui = "No"
            EndIf
            
            $aLVItems[$i][1] = $var2 & "|installed | program or software probably virus or keylogger |" & $ui
            $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
        EndIf
    Next

EndFunc ;==>genitems
;copied from
Func _FilterItem($sText)
    If ($sText = "") Then Return _ShowAll()
    For $i = $aLVItems[0][0] to 1 Step -1
        If NOT StringInStr(_GUICtrlListView_GetItemText($ListView1, $i-1), $sText) Then _GUICtrlListView_DeleteItem($ListView1, $i-1)
    Next
EndFunc  ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i

    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)

    For $i = 1 To $aLVItems[0][0]-1
        If $aLVItems[$i][1] = "" then Continueloop
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
EndFunc ;==>_ShowAll
Edited by ChrisL

Share this post


Link to post
Share on other sites

Thank you sir for that awesome help. Now i am happy!

how u know all these things that are not found in help file


Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Welcome

Which bit don't you think is in the help file?

Nah I cant explain it...

How to modify function abit? I want make it work so if all keys from registry are listed (no more registry keys left) then it read other elements (new ones) from *.txt file.

I have tried to do this with adding some stuff (if sentences, and adding new variables) but I failed :S

Text file is a bit tricky

1-st line contains program name

2-nd line contains description

3-rd ; 4-th and 5th line must be ignored so it could look like

and then text file repeats itself (with different names and descriptions :)

$line = 0
For $i = 1 to _FileCountLines("file.txt") / 5
$line = $line + 1
$text1 = FileReadLine("file.txt",$line)
$line = $line + 1
$text2 = FileReadLine("file.txt",$line)
$line = $line + 3;skip 3 lines

$aLVItems[$i][1] =$text1 & "|"&$isinstalled&"|"&$text2&"|" & $ui
$aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
next

Here is my way to check if program is already installed

;~ $text1 = "Adobe Flash Player 10 Plugin"
$text1 = FileReadLine(@MyDocumentsDir&"\install.txt",1)
$text2 = FileReadLine(@MyDocumentsDir&"\install.txt",2)

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $c = 1
    Do
        $c += 1
        RegEnumKey($Key, $c)
    Until @error
    $answer = ""

    
    For $i = 1 To $c
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
        If $var2 = $text1 Then
            MsgBox(1,1,"installed")
        $isinstalled = 1    
        ExitLoop
    EndIf
$isinstalled = 0    
    Next
        
If  $isinstalled = 1 Then
    $isinstalled = "installed"
Else 
    $isinstalled = "not installed"
EndIf   
$ui = "no"
$result = $text1 & "|"&$isinstalled&"|"&$text2&"|" & $ui
ClipPut($result)

Now how to add items from text file using these 2 things I posted?

and finally add alphabetical ordering (needed when adding elements from text file)to make it perfect, and then hardest part is over finally.

Edited by au3scr

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Do you only want the text file alphabetized or o you need all the reg keys and text file merged and alphabetized?

both after they are added in listview

Have you got a section from the text file you can post?

Here is text file, contains 3 programs

Mozilla Firefox (3.0.5)
Web browser
http://releases.mozilla.org/pub/mozilla.org/firefox/releases/3.0.5/win32/en-US/Firefox Setup 3.0.5.exe
FirefoxSetup3.0.5.exe
-ms
7-Zip 4.57
7-Zip is a file archiver with a high compression ratio.
http://autoit.pri.ee/downloads/7z457.exe
7z457.exe
/S
Adobe Flash Player 10 Plugin
Plugin you need to watch videos from youtube (for firefox)
http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player.exe
install_flash_player.exe
/S

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <array.au3>


Global $aLVItems

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1024, 800, 150, 85, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$input = GUICtrlCreateInput("", 125, 1, 125, 20)
$filterButton = GUICtrlCreateButton("Filter", 250, 1)
$ListView1 = GUICtrlCreateListView("Program Name|Program State|Program Descripton|Uninstall", 8, 72, 1009, 609, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_TRACKSELECT, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~;$item1 = GUICtrlCreateListViewItem("Solid Edge|Not Installed|Solid Edge is a 3D CAD parametric feature solid modeling software.", $ListView1)
;~;$item2 = GUICtrlCreateListViewItem("AutoIt|Installed|AutoIt (pronounced aw-tow-it)[1] is a freeware automation language for Microsoft Windows.", $ListView1)
genitems()
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($ListView1, 2, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton("Get program name", 1, 1, 120, 20)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            _GetProgramName()
        Case $filterButton
            _FilterItem(GUICtrlRead($input))
    EndSwitch
WEnd


Func _GetProgramName()
    $sel = _GUICtrlListView_GetSelectedIndices($ListView1, True)
    If $sel[0] = 0 Then Return; exit if none is selected
    $sName = _GUICtrlListView_GetItemText($ListView1, $sel[1], 0);Get 0th column text
    MsgBox(0, "", $sName, -1, $Form1)
EndFunc  ;==>_GetProgramName

Func genitems()

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $c = 1
    Do
        $c += 1
        RegEnumKey($Key, $c)
    Until @error
    $answer = ""
    
    Dim $aLVItems[$c][2]
    $aLVItems[0][0] = $c
    
    For $i = 1 To $c
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
;~;  $answer = $answer & @CRLF & "KeyName=" & @CRLF & $var & "Program name="& $var2 & @CRLF  &"Uninstall command=" & $var3 & @CRLF & "Quiet uninstall=" &$var4
;~; ShellExecute($var3)
        If Not $var2 = "" Then
            $ui = "Yes"
            If $var3 = "" Then
                $ui = "No"
            EndIf
            
            $aLVItems[$i][1] = $var2 & "|installed | program or software probably virus or keylogger |" & $ui
            
        EndIf
    Next
    
    $File = FileRead("TextFile.txt");Read in the text file
    $aSplit = StringSplit($File,@crlf,1);Spit the text file in to an array
    For $i = 1 to Ubound($aSplit) -1 Step 5;read every 5th line
            
            ReDim $aLVItems[$aLVItems[0][0] +2][2];resize the listview items array for each new element
            $aLVItems[0][0] +=1;change the array counter +1
            $aLVItems[$aLVItems[0][0]][1] = $aSplit[$i] & "|Not sure how you want this|" & $aSplit[$i +1] & "|or this bit";add in the listview text tot he listview array
    Next
        
    
    _ArraySort($aLVItems,0,1,0,1);Sort the array before inserting on the Program Name
    
;Populate the listview
    For $i = 1 to $aLVItems[0][0]   
        If $aLVItems[$i][1] <> "" then $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
    
EndFunc  ;==>genitems
;copied from
Func _FilterItem($sText)
    If ($sText = "") Then Return _ShowAll()
    For $i = $aLVItems[0][0] to 1 Step -1
        If NOT StringInStr(_GUICtrlListView_GetItemText($ListView1, $i-1), $sText) Then _GUICtrlListView_DeleteItem($ListView1, $i-1)
    Next
EndFunc  ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i

    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)

    For $i = 1 To $aLVItems[0][0]-1
        If $aLVItems[$i][1] = "" then Continueloop
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
EndFunc  ;==>_ShowAll

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Does anyone know reason of this?

@ChrisL Did you tested that script on ur computer? I wanna know if i am only one who got that error !

I mean how i can get rid of this message

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "Z:\My Documents\11-2008\myscript.au3"

Z:\My Documents\11-2008\myscript.au3 (86) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aLVItems[$aLVItems[0][0]][1] = $aSplit[$i] & "|Not sure how you want this|" & $aSplit[$i +1] & "|or this bit"

$aLVItems[$aLVItems[0][0]][1] = $aSplit[$i] & "|Not sure how you want this|" & ^ ERROR

Edited by au3scr

Share this post


Link to post
Share on other sites

Does anyone know reason of this?

@ChrisL Did you tested that script on ur computer? I wanna know if i am only one who got that error !

I mean how i can get rid of this messaga

It's because I used the example of the text file you posted.

Your text file must be incorrect. perhaps it needs a bit more error handling in it.. and yes I did test it on my computer

Share this post


Link to post
Share on other sites

Any good?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <array.au3>


Global $aLVItems

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1024, 800, 150, 85, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$input = GUICtrlCreateInput("", 125, 1, 125, 20)
$filterButton = GUICtrlCreateButton("Filter", 250, 1)
$ListView1 = GUICtrlCreateListView("Program Name|Program State|Program Descripton|Uninstall", 8, 72, 1009, 609, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_TRACKSELECT, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~;$item1 = GUICtrlCreateListViewItem("Solid Edge|Not Installed|Solid Edge is a 3D CAD parametric feature solid modeling software.", $ListView1)
;~;$item2 = GUICtrlCreateListViewItem("AutoIt|Installed|AutoIt (pronounced aw-tow-it)[1] is a freeware automation language for Microsoft Windows.", $ListView1)
genitems()
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($ListView1, 2, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton("Get program name", 1, 1, 120, 20)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            _GetProgramName()
        Case $filterButton
            _FilterItem(GUICtrlRead($input))
    EndSwitch
WEnd


Func _GetProgramName()
    $sel = _GUICtrlListView_GetSelectedIndices($ListView1, True)
    If $sel[0] = 0 Then Return; exit if none is selected
    $sName = _GUICtrlListView_GetItemText($ListView1, $sel[1], 0);Get 0th column text
    MsgBox(0, "", $sName, -1, $Form1)
EndFunc  ;==>_GetProgramName

Func genitems()

    $Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $c = 1
    Do
        $c += 1
        RegEnumKey($Key, $c)
    Until @error
    $answer = ""
    
    Dim $aLVItems[$c][2]
    $aLVItems[0][0] = $c
    
    For $i = 1 To $c
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
;~;  $answer = $answer & @CRLF & "KeyName=" & @CRLF & $var & "Program name="& $var2 & @CRLF  &"Uninstall command=" & $var3 & @CRLF & "Quiet uninstall=" &$var4
;~; ShellExecute($var3)
        If Not $var2 = "" Then
            $ui = "Yes"
            If $var3 = "" Then
                $ui = "No"
            EndIf
            
            $aLVItems[$i][1] = $var2 & "|installed | program or software probably virus or keylogger |" & $ui
            
        EndIf
    Next
    
    $File = FileRead("TextFile.txt");Read in the text file
    $aSplit = StringSplit($File,@crlf,1);Spit the text file in to an array
    For $i = 1 to Ubound($aSplit) -1 Step 5;read every 5th line
            
            ReDim $aLVItems[$aLVItems[0][0] +2][2];resize the listview items array for each new element
            $aLVItems[0][0] +=1;change the array counter +1
            
            If $i < $aSplit[0] and $i +1 < $aSplit[0] then $aLVItems[$aLVItems[0][0]][1] = $aSplit[$i] & "|Not sure how you want this|" & $aSplit[$i +1] & "|or this bit";add in the listview text to the listview array
            
    Next
        
    
    _ArraySort($aLVItems,0,1,0,1);Sort the array before inserting on the Program Name
    
;Populate the listview
    For $i = 1 to $aLVItems[0][0]   
        If $aLVItems[$i][1] <> "" then $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
    
EndFunc  ;==>genitems
;copied from
Func _FilterItem($sText)
    If ($sText = "") Then Return _ShowAll()
    For $i = $aLVItems[0][0] to 1 Step -1
        If NOT StringInStr(_GUICtrlListView_GetItemText($ListView1, $i-1), $sText) Then _GUICtrlListView_DeleteItem($ListView1, $i-1)
    Next
EndFunc  ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i

    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)

    For $i = 1 To $aLVItems[0][0]-1
        If $aLVItems[$i][1] = "" then Continueloop
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1], $ListView1)
    Next
EndFunc  ;==>_ShowAll

Share this post


Link to post
Share on other sites

good I like that you are so helpful :)

|Not sure how you want this|

following code is example how fill program state , check if program is installed look at variable $isinstalled

and uninstall column is easy too if program is not installed or if its installed but uninstall is impossible then print "no" in uninstall column

Thise 2 things i mentioned should be easy I suppose and i guess I can do it my self,but the harder thing where i would like some help is remove duplicate items Removing duplicate items should work thatway script looks both program name and program description and if there are 2 or more exactly same items (name&description) then it leaves only 1 of them(ao all items are unique).

For me GUI has always been hardest part of program,Most my scripts works with out giving user any chance control it,and about 95 % of my scripts have no gui, thats why I ask so much help about that listview.

;~ $text1 = "Adobe Flash Player 10 Plugin"

$text1 = FileReadLine(@MyDocumentsDir&"\install.txt",1)

$text2 = FileReadLine(@MyDocumentsDir&"\install.txt",2)

$Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

$c = 1

Do

$c += 1

RegEnumKey($Key, $c)

Until @error

$answer = ""

For $i = 1 To $c

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)

If @error <> 0 Then ExitLoop

$var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")

$var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")

$var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")

If $var2 = $text1 Then

MsgBox(1,1,"installed")

$isinstalled = 1

ExitLoop

EndIf

$isinstalled = 0

Next

If $isinstalled = 1 Then

$isinstalled = "installed"

Else

$isinstalled = "not installed"

EndIf

$ui = "no"

$result = $text1 & "|"&$isinstalled&"|"&$text2&"|" & $ui

ClipPut($result)


Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Its using a 5 coumn 2D array now

genitems() has changed quite a bit from how it was

Blanks are now not added in to the array from the registry so no need to check and duplicates are marked as [{Dupicate}] and not added to the listview

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <array.au3>


Global $aLVItems

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1024, 800, 150, 85, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$input = GUICtrlCreateInput("", 125, 1, 125, 20)
$filterButton = GUICtrlCreateButton("Filter", 250, 1)
$ListView1 = GUICtrlCreateListView("Program Name|Program State|Program Descripton|Uninstall", 8, 72, 1009, 609, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_HSCROLL, $WS_VSCROLL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_SUBITEMIMAGES, $LVS_EX_TRACKSELECT, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~;$item1 = GUICtrlCreateListViewItem("Solid Edge|Not Installed|Solid Edge is a 3D CAD parametric feature solid modeling software.", $ListView1)
;~;$item2 = GUICtrlCreateListViewItem("AutoIt|Installed|AutoIt (pronounced aw-tow-it)[1] is a freeware automation language for Microsoft Windows.", $ListView1)
genitems()
_GUICtrlListView_SetColumnWidth($ListView1, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($ListView1, 2, $LVSCW_AUTOSIZE)
GUISetState(@SW_SHOW)
$button = GUICtrlCreateButton("Get program name", 1, 1, 120, 20)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            _GetProgramName()
        Case $filterButton
            _FilterItem(GUICtrlRead($input))
    EndSwitch
WEnd


Func _GetProgramName()
    $sel = _GUICtrlListView_GetSelectedIndices($ListView1, True)
    If $sel[0] = 0 Then Return; exit if none is selected
    $sName = _GUICtrlListView_GetItemText($ListView1, $sel[1], 0);Get 0th column text
    MsgBox(0, "", $sName, -1, $Form1)
EndFunc ;==>_GetProgramName

Func genitems()
    
    Dim $aLVItems[1][5];Change it to 5 column array to store each section then we can check the columns 1 and 3 for duplicates
    $aLVItems[0][0] = 0
    $i =0
    While 1 
        $i +=1
        $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
        If @error <> 0 Then ExitLoop
        $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "DisplayName")
        If $Var2 = "" then Continueloop;Blanks never get populated so why bother adding them move on to the next loop
        
        $var3 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "UninstallString")
        $var4 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $var, "QuietUninstallString")
;~;  $answer = $answer & @CRLF & "KeyName=" & @CRLF & $var & "Program name="& $var2 & @CRLF  &"Uninstall command=" & $var3 & @CRLF & "Quiet uninstall=" &$var4
;~; ShellExecute($var3)
        If Not $var2 = "" Then $ui = "Yes";Not sure why you need this $Var2 will never be "" because we skip blanks
            
        If $var3 = "" Then
            $ui = "No"
        EndIf

        $aLVItems[0][0] +=1; keep the array count
        Redim $aLVItems[$aLVItems[0][0] +1][5];resize the array
        $aLVItems[$aLVItems[0][0]][1] = $var2 
        $aLVItems[$aLVItems[0][0]][2] = "installed"
        $aLVItems[$aLVItems[0][0]][3] = "program or software probably virus or keylogger"
        $aLVItems[$aLVItems[0][0]][4] = $ui

    Wend
    
    $File = FileRead("TextFile.txt");Read in the text file
    $aSplit = StringSplit($File,@crlf,1);Spit the text file in to an array
    For $i = 1 to Ubound($aSplit) -1 Step 5;read every 5th line
            
            ReDim $aLVItems[$aLVItems[0][0] +2][5];resize the listview items array for each new element
            $aLVItems[0][0] +=1;change the array counter +1
            
            If $i < $aSplit[0] and $i +1 < $aSplit[0] then 
                $aLVItems[$aLVItems[0][0]][1] = $aSplit[$i] 
                $aLVItems[$aLVItems[0][0]][2] = "Not sure how you want this" 
                $aLVItems[$aLVItems[0][0]][3] = $aSplit[$i +1] 
                $aLVItems[$aLVItems[0][0]][4] = "or this bit"
            EndIf
    
    Next
        
    _ArraySort($aLVItems,0,1,0,1);Sort the array before inserting on the Program Name also makes finding duplicates easier


    For $i = 1 to $aLVItems[0][0] 
        If $i +1 <= $aLVItems[0][0] then 
            For $x = ($i+1) to $aLVItems[0][0];check the next line(s) for a duplicates, we can check sequencialy because the array is sorted alphabetically as soon as there is no match we can move on
                If $aLVItems[$i][1] <> "[{Duplicate}]" and $aLVItems[$i][1] = $aLVItems[$x][1] and $aLVItems[$i][3] = $aLVItems[$x][3] then 
                    $aLVItems[$x][1] = "[{Duplicate}]"
                Else
                    Exitloop;There is no match exit loop and move on to check the next line for a duplicate entry
                EndIf
            Next
        EndIf
        
        If $aLVItems[$i][1] <> "[{Duplicate}]" then $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1] & "|" & $aLVItems[$i][2] & "|" & $aLVItems[$i][3] & "|" & $aLVItems[$i][4]  , $ListView1)
    Next

EndFunc ;==>genitems

;copied from
Func _FilterItem($sText)
    If ($sText = "") Then Return _ShowAll()
    For $i = $aLVItems[0][0] to 1 Step -1
        If NOT StringInStr(_GUICtrlListView_GetItemText($ListView1, $i-1), $sText) Then _GUICtrlListView_DeleteItem($ListView1, $i-1)
    Next
EndFunc ;==>_FilterItem

Func _ShowAll()
    If GUICtrlSendMsg($ListView1, $LVM_GETITEMCOUNT, 0, 0) = $aLVItems[0][0] Then Return
   
    Local $i

    GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)

    For $i = 1 To $aLVItems[0][0]-1
        If $aLVItems[$i][1] = "[{Duplicate}]" then Continueloop
        $aLVItems[$i][0] = GUICtrlCreateListViewItem($aLVItems[$i][1] & "|" & $aLVItems[$i][2] & "|" & $aLVItems[$i][3] & "|" & $aLVItems[$i][4], $ListView1)
    Next
EndFunc ;==>_ShowAll
Edited by ChrisL

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