Jump to content
Sign in to follow this  
peomalle

Need help in exporting a GUICtrlCreateListView control to a CSV file

Recommended Posts

peomalle

Objective: To be able to export the contents of a populated GUICtrlCreateListView control to a CSV file.

Through the many excellent contributions to this forum, I was able to GUICtrlCreateListView control to show exactly what I wanted (installed Software, minus a select few application). However, I tried and tried to get the contents of the control exported to a CSV file (or even a simple text file) and have not succeed.

Any guidance would be most appreciated.

#include <GuiListView.au3>
#include <file.au3>
#include <Array.au3>
AutoItSetOption("TrayAutoPause", 0)
;Enable OnEvent functions notifications.
AutoItSetOption('GUIOnEventMode', 1)
AutoItSetOption('GUICloseOnEsc', 1)
$Log = (@TempDir & "\" & "ListofInstalledApps_" & @UserName & ".csv")
Global $i
Local $sSft
;Create a GUI window
Global $sGui = GUICreate('Currently installed software on your ' & @OSVersion & ' machine', 810, 650, -1, -1)
;Creates a ListView control for the above GUI.
Global $sLvw = GUICtrlCreateListView('#|Installed Software|Display Version|Publisher', 5, 5, 800, 600)
_ComputerGetSoftware($sSft)

For $i = 1 To UBound($sSft) - 1
GUICtrlCreateListViewItem($i & '|' & $sSft[$i][0] & '|' & $sSft[$i][1] & '|' & $sSft[$i][2], $sLvw)
Next
GUICtrlSendMsg($sLvw, 0x101E, 1, 200)
GUICtrlSendMsg($sLvw, 0x101E, 2, 65)
GUICtrlSendMsg($sLvw, 0x101E, 3, 250)
Local $mMen = GUICtrlCreateContextMenu($sLvw)
;Local $CopI = GUICtrlCreateMenuItem('Uninstall Current Selection', $mMen)
;GUICtrlSetOnEvent($CopI, '_Uninstall')
Local $exp = GUICtrlCreateButton('Auto Fit', 560, 615, 100)
GUICtrlSetOnEvent($exp, '_Expand')
GUISetOnEvent(-3, '_AllExit')
GUISetState(@SW_SHOW, $sGui)
Local $send2CSV = GUICtrlCreateButton('Send to CSV File', 700, 615, 100)
GUICtrlSetOnEvent($send2CSV, '_send2CSV')

While 1
Sleep(10)
WEnd
;
Func _AllExit()
GUIDelete($sGui)
Exit
EndFunc   ;==>_AllExit

Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Local $i = 1
;Create an array.
Dim $aSoftwareInfo[1][3]
For $j = 1 To 500
  $AppKey = RegEnumKey($UnInstKey, $j)
  If @error <> 0 Then ExitLoop
  If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
  ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][3]
  $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
  If StringInStr($aSoftwareInfo[$i][0], "Security Update for") Then ContinueLoop
  If StringInStr($aSoftwareInfo[$i][0], "Update for Windows XP") Then ContinueLoop
  If StringInStr($aSoftwareInfo[$i][0], "Hotfix for Windows XP") Then ContinueLoop
  $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
  $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
  $i = $i + 1
Next

$aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)
;Go through the array from bottom to top
;If Column2 (Installed Software) is blank...delete the whole "row" of the array
For $i = UBound($aSoftwareInfo) - 1 To 0 Step -1
  If $aSoftwareInfo[$i][1] = "" Then
   _ArrayDelete($aSoftwareInfo, $i)
  EndIf
Next
;Sort the array, acending, by column 1 ('DisplayName')
Return _ArraySort($aSoftwareInfo, 0, 1)
EndFunc   ;==>_ComputerGetSoftware

Func _Expand()
_GUICtrlListView_SetColumnWidth($sLvw, 1, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($sLvw, 2, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($sLvw, 3, $LVSCW_AUTOSIZE)
EndFunc   ;==>_Expand
Func _Send2CSV()
;Need Help
EndFunc   ;==>_Send2CSV

Share this post


Link to post
Share on other sites
BrewManNH

Check out by guinness, he has a function that will do that for you.


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

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  

×