Sign in to follow this  
Followers 0
jazzyjeff

Refresh GUICtrlCreateListView

4 posts in this topic

Hello,

I have been tasked to create a little app that will allow students to install software that we specify. The installation part works fine, but the part I am having problems with is determining the current versio installed.

I am using WMI to scan the PC for the current version of specified apps, and this also works. It populates the correct column with the current software version.

The problem is that this scan takes a little while, and I have the check performed at the started of the script, so when the user runs the exe it appears that nothing is happening and then all of a sudden the GUI appears. I have tried opening the GUI first and then run the WMI check, but it never populates the column. I have to perform the check before the GUI appears. I am thinking there must be a way to refresh the columns, but I couldn't get it to work.

I saw the function _GUICtrlListView_BeginUpdate, but I couldn't get this to work.

If someone can offer some help, it would be appreciated. My code is below. Thanks.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=D:\Icons\School.ico
#AutoIt3Wrapper_outfile=X:\Applications-Installers\Utilities\One2One Apps\Student-Installer.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $oAdobeFlash,$oAdobeReader,$FormChk
;Check Software versions
_AdobeFlashChk()
_AdobeReaderChk()

;Start Interface
$formMain = GUICreate("Student App Store", 500, 192, 201, 124)
$listSoftware = GUICtrlCreateListView("", 8, 8, 400, 175)
; Add columns
_GUICtrlListView_AddColumn($listSoftware, "Software", 120)
_GUICtrlListView_AddColumn($listSoftware, "Installed", 80)
_GUICtrlListView_AddColumn($listSoftware, "Number of Installs", 115)
_GUICtrlListView_AddColumn($listSoftware, "Availability", 80)
; Add items
_GUICtrlListView_AddItem($listSoftware, "Adobe Flash")
_GUICtrlListView_AddSubItem($listSoftware, 0, $oAdobeFlash,1)
_GUICtrlListView_AddItem($listSoftware, "Adobe Reader")
_GUICtrlListView_AddSubItem($listSoftware, 1, $oAdobeReader,1)
$btnInstall = GUICtrlCreateButton("&Install", 417, 112, 75, 25, $WS_GROUP)
$btnUninstall = GUICtrlCreateButton("&Uninstall", 417, 136, 75, 25, $WS_GROUP)
$btnExit = GUICtrlCreateButton("E&xit", 417, 160, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnExit
            Exit
        Case $btnInstall
            If _GUICtrlListView_GetItemSelected($listSoftware,0) Then
                _AdobeFlash()
            ElseIf _GUICtrlListView_GetItemSelected($listSoftware,1) Then
                _AdobeReader()
            EndIf
    EndSwitch
WEnd

;Software Installation functions
Func _AdobeReader()
    RunAsWait("username","domain","password",0,"\\server\sharename$\Scripts\Applications\Adobe\Adobe Reader - Install.exe")
EndFunc

Func _AdobeFlash()
    RunAsWait("username","domain","password",0,"\\server\sharename$\Scripts\Applications\Adobe\Adobe Flash - Install.exe")
EndFunc

;Software version check
Func _AdobeReaderChk()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $Output = $Output & "==========================================" & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
    $colItems = $objWMIService.ExecQuery("SELECT Version FROM Win32_Product WHERE Name='Adobe Reader 9.4.0'", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $oAdobeReader = $objItem.Version
        Next
    Else
        Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Product" )
    EndIf
EndFunc

Func _AdobeFlashChk()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $Output = $Output & "==========================================" & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
    $colItems = $objWMIService.ExecQuery("SELECT Version FROM Win32_Product WHERE Name='Adobe Flash Player 10 ActiveX'", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $oAdobeFlash = $objItem.Version
        Next
    Else
        Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Product" )
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



Try adding this to let them know it's doing something when they start the program. Customize as you see fit.:

(see the lines marked <<<<<<<<<<<<<<<<<<<<<<< below)

Global $SplashScreen = GUICreate("", 200, 100, -1, -1, $WS_POPUP) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $SplashLabel = GUICtrlCreateLabel("Searching...", 20, 20, 150, 50) ; <<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetFont(-1, 20, 800) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_AdobeFlashChk()
_AdobeReaderChk()
GuiDelete($SplashScreen) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

This pops up a screen letting them know that the program has started, depending upon the speed of the search this may only be up for a second, but at least it gives an indication that it's running.


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

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

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

Share this post


Link to post
Share on other sites

I tried this as a workaround too, but it would never launch the other screen. It's like it was stuck on the first window. I got the same idea working in another script. Really though it's not what I am looking for, so I wasn't planning on spending much time getting it to work. I am really hoping for a refresh of the listview. It seems like it should be possible, I just haven't found a way to do it.

Thanks for the idea.

Share this post


Link to post
Share on other sites

Hey you know what, I figured this out!

Here is what I did:

GUISetState(@SW_SHOW)
_AdobeFlashChk()
_AdobeReaderChk()
_GUICtrlListView_AddSubItem($listSoftware, 0, $oAdobeFlash,1)
_GUICtrlListView_AddSubItem($listSoftware, 1, $oAdobeReader,1)

After the GUI was loaded, I then ran the WMI check and then reloaded the software versions in the listview.

Problem solved!

Thanks taking a look at this.

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