mucitbey Posted February 24, 2020 Share Posted February 24, 2020 I want to display the data in the ini file with ListView (then query with this data). Is there anyone who can help with this? Thank you to those who helped in advance. Update.ini [100.162.160.77] PCT-CG0006S1|sysm.drums=Updated. [100.162.160.44] PCT-F4480Y6P|fkrt.ytmurk=Updated. [100.162.160.11] PCF-CG0006R8|memn.gnslps=Updated. PCF-CG0006R8|ssmt.krkrn=Updated. PCF-CG0006R8|rdnc.strongs=Updated. [100.162.160.21] PCT-S01GMTX1|kmlttn.kskln=Updated. [100.162.160.73] PCX-CG0006M5|Administrator=Updated. PCX-CG0006M5|rtgrl.krks=Updated. PCX-CG0006M5|srnyn.horsn=Updated. I did a study like this, but I could not get all the data. #include <Array.au3> #include <GUIConstants.au3> $gui = GUICreate("ListBiew items", 400, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("IP|PC NAME|USER NAME|STATUS", 10, 10, 380, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() ;$File = FileOpenDialog("Select INI file", "", "(*.ini)") $File = @ScriptDir &"\Update.ini" $Sect = IniReadSectionNames($File) For $i = 1 To $Sect[0] $list = IniReadSection($File, $Sect[$i]) $tmp = '' For $x = 1 To $list[0][0] $tmp &= $list[$x][1] &"|" Next $tmp = StringTrimRight($tmp,1) GUICtrlCreateListViewItem($Sect[$i] &"|"& $tmp, $listview) Next GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Link to comment Share on other sites More sharing options...
Gianni Posted February 24, 2020 Share Posted February 24, 2020 try this little change to your script #include <Array.au3> #include <GUIConstants.au3> $gui = GUICreate("ListBiew items", 400, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("IP|PC NAME|USER NAME|STATUS", 10, 10, 380, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() ;$File = FileOpenDialog("Select INI file", "", "(*.ini)") $File = @ScriptDir & "\Update.ini" $Sect = IniReadSectionNames($File) For $i = 1 To $Sect[0] $list = IniReadSection($File, $Sect[$i]) For $x = 1 To $list[0][0] $tmp = '' $tmp &= $list[$x][0] & '|' & $list[$x][1] ; & "|" GUICtrlCreateListViewItem($Sect[$i] & "|" & $tmp, $listview) Next Next GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE mucitbey 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mucitbey Posted February 24, 2020 Author Share Posted February 24, 2020 (edited) First, thanks again for the help #Chimp.I have one more question how can we edit the same process according to this ini file. Loginfo.ini [20200103] 100.162.160.11|PCF-CG0006R8|memn.gnslpsMicrosoft Windows 10 Enterprise 2016 LTSB|14393|A0-1073741824-667|A1-1073741824-667||3.01.2020 19:37:30 100.162.160.11|PCF-CG0006R8|ssmt.krkrnMicrosoft Windows 10 Enterprise 2016 LTSB|14393|A0-1073741824-667|A1-1073741824-667||3.01.2020 19:36:49 100.162.160.77|PCT-CG0006S1|sysm.drums|Microsoft Windows 10 Enterprise 2016 LTSB|14393|ChannelA-DIMM0-4294967296-2400|ChannelB-DIMM0-4294967296-2400||03.01.2020 16:50:36 [20200104] 100.162.160.73|PCX-CG0006M5|Administrato|Microsoft Windows 10 Enterprise|14393|XMM3-2147483648-1333|XMM4-2147483648-1333|SYSTEM ROM-1048576-||3.01.2020 16:16:27 100.162.160.73|PCX-CG0006M5|rtgrl.krks|Microsoft Windows 10 Enterprise|14393|XMM3-2147483648-1333|XMM4-2147483648-1333|SYSTEM ROM-1048576-||3.01.2020 16:15:58 [20200105] 100.162.160.44|PCT-F4480Y6P|fkrt.ytmurk|Microsoft Windows 10 Enterprise 2016 LTSB|14393|ChannelA-DIMM0-8589934592-2400||03.01.2020 15:31:32 I adapted the same codes to this, but that didn't work. #include <Array.au3> #include <GUIConstants.au3> $gui = GUICreate("ListBiew items", 1000, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("DATE|IP|PC NAME|USER NAME|OS TYPE|OS VER|DIMM 1|DIMM 2|DATE-TIME", 10, 10, 380, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() ;$File = FileOpenDialog("Select INI file", "", "(*.ini)") $File = @ScriptDir & "\Loginfo.ini" $Sect = IniReadSectionNames($File) For $i = 1 To $Sect[0] $list = IniReadSection($File, $Sect[$i]) For $x = 1 To $list[0][0] $tmp = '' $tmp &= $list[$x][0] & '|' & $list[$x][1] ; & "|" GUICtrlCreateListViewItem($Sect[$i] & "|" & $tmp, $listview) Next Next GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Thanks. Edited February 24, 2020 by mucitbey Link to comment Share on other sites More sharing options...
Musashi Posted February 24, 2020 Share Posted February 24, 2020 (edited) 34 minutes ago, mucitbey said: I adapted the same codes to this, but that didn't work. IniReadSection fails (@error = 1) because -> a standard ini file looks like:[SectionName] Key=Value You have only Keys in your sections (no =Values). Edited February 24, 2020 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
mucitbey Posted February 24, 2020 Author Share Posted February 24, 2020 29 minutes ago, Musashi said: IniReadSection fails (@error = 1) because -> a standard ini file looks like:[SectionName] Key=Value You have only Keys in your sections (no =Values). Is there any other solution to read the data in this ini file? Link to comment Share on other sites More sharing options...
Musashi Posted February 24, 2020 Share Posted February 24, 2020 37 minutes ago, mucitbey said: Is there any other solution to read the data in this ini file? #include <Array.au3> #include <File.au3> #include <GUIConstants.au3> Global $aRetArray, $sSection = "" $gui = GUICreate("ListView items", 1000, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("DATE|IP|PC NAME|USER NAME|OS TYPE|OS VER|DIMM 1|DIMM 2|DATE-TIME|-|-", 10, 10, 980, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() _FileReadToArray(@ScriptDir & "\Loginfo.ini", $aRetArray) For $i = 1 To $aRetArray[0] Step 1 ConsoleWrite($aRetArray[$i] & @CRLF) ; *** just for display If StringRegExp($aRetArray[$i], "^\[\d{8}\]$") Then $sSection = $aRetArray[$i] Else GUICtrlCreateListViewItem($sSection & "|" & $aRetArray[$i], $listview) EndIf Next GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Check your Delimiter | in the .ini ! mucitbey 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
mucitbey Posted February 24, 2020 Author Share Posted February 24, 2020 12 minutes ago, Musashi said: #include <Array.au3> #include <File.au3> #include <GUIConstants.au3> Global $aRetArray, $sSection = "" $gui = GUICreate("ListView items", 1000, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("DATE|IP|PC NAME|USER NAME|OS TYPE|OS VER|DIMM 1|DIMM 2|DATE-TIME|-|-", 10, 10, 980, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() _FileReadToArray(@ScriptDir & "\Loginfo.ini", $aRetArray) For $i = 1 To $aRetArray[0] Step 1 ConsoleWrite($aRetArray[$i] & @CRLF) ; *** just for display If StringRegExp($aRetArray[$i], "^\[\d{8}\]$") Then $sSection = $aRetArray[$i] Else GUICtrlCreateListViewItem($sSection & "|" & $aRetArray[$i], $listview) EndIf Next GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Check your Delimiter | in the .ini ! Thank you for your help and guidance. the #Musashi Link to comment Share on other sites More sharing options...
Musashi Posted February 24, 2020 Share Posted February 24, 2020 16 minutes ago, mucitbey said: Thank you for your help and guidance @Musashi No problem 🙂. But please check the delimiters in your loginfo.ini. The number of delimiters is not identical, so some entries do not match the headline, see : Spoiler [20200103] 100.162.160.11 |PCF-CG0006R8 |memn.gnslpsMicrosoft Windows 10 Enterprise 2016 LTSB |14393 |A0-1073741824-667 |A1-1073741824-667 | |3.01.2020 19:37:30 [20200104] 100.162.160.73 |PCX-CG0006M5 |Administrato |Microsoft Windows 10 Enterprise |14393 |XMM3-2147483648-1333 |XMM4-2147483648-1333 |SYSTEM ROM-1048576- | |3.01.2020 16:16:27 mucitbey 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Gianni Posted February 24, 2020 Share Posted February 24, 2020 (edited) as already pointed out by Musashi, your ini file is misconfigured: It doesn't include the key=value pairs and it also has a "variable" number of "columns" on random records. For first problem you can use as a workaround the insertion of the "=" sign as the last character of the string in the ini file while for the mismatch of columns you have to solve by ensure that each "row" in the ini file is correctly formatted here the Loginfo.ini file with the "=" workaround [20200103] 100.162.160.11|PCF-CG0006R8|memn.gnslpsMicrosoft Windows 10 Enterprise 2016 LTSB|14393|A0-1073741824-667|A1-1073741824-667||3.01.2020 19:37:30= 100.162.160.11|PCF-CG0006R8|ssmt.krkrnMicrosoft Windows 10 Enterprise 2016 LTSB|14393|A0-1073741824-667|A1-1073741824-667||3.01.2020 19:36:49= 100.162.160.77|PCT-CG0006S1|sysm.drums|Microsoft Windows 10 Enterprise 2016 LTSB|14393|ChannelA-DIMM0-4294967296-2400|ChannelB-DIMM0-4294967296-2400||03.01.2020 16:50:36= [20200104] 100.162.160.73|PCX-CG0006M5|Administrato|Microsoft Windows 10 Enterprise|14393|XMM3-2147483648-1333|XMM4-2147483648-1333|SYSTEM ROM-1048576-||3.01.2020 16:16:27= 100.162.160.73|PCX-CG0006M5|rtgrl.krks|Microsoft Windows 10 Enterprise|14393|XMM3-2147483648-1333|XMM4-2147483648-1333|SYSTEM ROM-1048576-||3.01.2020 16:15:58= [20200105] 100.162.160.44|PCT-F4480Y6P|fkrt.ytmurk|Microsoft Windows 10 Enterprise 2016 LTSB|14393|ChannelA-DIMM0-8589934592-2400||03.01.2020 15:31:32= while for the mismatch of columns, istead of trying to auto-match data with columns, I think that ensure that each "row" in the ini file is correctly formatted should be a better choice. The following modified version of your script will show you the wrong "records" #include <Array.au3> #include <GUIConstants.au3> $gui = GUICreate("ListBiew items", 1000, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("DATE|IP|PC NAME|USER NAME|OS TYPE|OS VER|DIMM 1|DIMM 2|DATE-TIME", 10, 10, 380, 280) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() ;$File = FileOpenDialog("Select INI file", "", "(*.ini)") $File = @ScriptDir & "\Loginfo.ini" $Sect = IniReadSectionNames($File) For $i = 1 To $Sect[0] $list = IniReadSection($File, $Sect[$i]) For $x = 1 To $list[0][0] ; check for columns mismatch errors StringReplace($list[$x][0], '|', '|') $iSeparators = @extended If $iSeparators > 8 Then GUICtrlCreateListViewItem("Columns Mismatch error.", $listview) Else GUICtrlCreateListViewItem($list[$x][0], $listview) ; $Sect[$i] & "|" & $tmp, $listview) EndIf Next Next GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 100) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Edited February 24, 2020 by Chimp mucitbey 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Musashi Posted February 24, 2020 Share Posted February 24, 2020 First of all : "There is nothing wrong with the work-around suggested by @Chimp !" The question that pops into my mind (and Chimp's mind certainly as well) is : Which program or process generates this loginfo.ini ? Is it possible, that you (or someone in your environment) create this file and only use the ini-format because you know it best ? I find it hard to imagine, that a professional software would create such a malformed .ini. We may be able to offer a better solution, if we know the genesis of this file . Gianni and mucitbey 1 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now