Jump to content

About data stream extraction


i2i8
 Share

Go to solution Solved by AllenAA,

Recommended Posts

 Hello everyone, hope to get your help . I have a stream of data that looks like this:

PS C:\> Dism /Get-ImageInfo /ImageFile:H:\sources\install.wim /English /Format:Table

Deployment Image Servicing and Management tool
Version: 10.0.19041.844

Details for image : H:\sources\install.wim

Index : 1
Name : Windows Server 2016 Standard
Description : This option (recommended) reduces management and servicing by installing only what is needed to run most server roles and applications. It does not include a GUI, but you can fully manage the server locally or remotely with Windows PowerShell or other tools. For more details see "Windows Server Installation Options."
Size : 9,180,501,839 bytes

Index : 2
Name : Windows Server 2016 Standard (Desktop Experience)
Description : This option is useful when a GUI is required—for example, to provide backward compatibility for an application that cannot be run on a Server Core installation. All server roles and features are supported. For more details see "Windows Server Installation Options."
Size : 15,196,490,590 bytes

Index : 3
Name : Windows Server 2016 Datacenter
Description : This option (recommended) reduces management and servicing by installing only what is needed to run most server roles and applications. It does not include a GUI, but you can fully manage the server locally or remotely with Windows PowerShell or other tools. For more details see "Windows Server Installation Options."
Size : 9,175,696,563 bytes

Index : 4
Name : Windows Server 2016 Datacenter (Desktop Experience)
Description : This option is useful when a GUI is required—for example, to provide backward compatibility for an application that cannot be run on a Server Core installation. All server roles and features are supported. For more details see "Windows Server Installation Options."
Size : 15,198,865,664 bytes

The operation completed successfully.

I want to extract the index row and the Name row and add the Name row to GUICtrlCreateCombo, and when I select Windows Server 2016 Standard, return its index value 1, When I select Windows Server 2016 Datacenter, the index value 3 is returned. How do I implement this?

 ex:

#RequireAdmin
#include-once
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Global $BoFile                                              ; boot.wim Path
Global $MoFile                                              ; install.wim OR install.esd Path
Global $DISM_PATH = @SystemDir & '\Dism.exe'

GuiMain()

While 1
    Sleep(80) ; Sleep to reduce CPU usage
WEnd

Func GuiMain()
    Global $Main = GUICreate("MosBoot", 600, 300, -1, -1)
    Global $BtnSoFileShow = GUICtrlCreateInput("install.wim Or install.esd", 16, 89, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $Panel = GUICtrlCreateGroup("", 8, 0, 584, 291)
    Global $BtnSoFileFind = GUICtrlCreateButton("install", 507, 88, 75, 25)
    GUICtrlSetOnEvent($BtnSoFileFind, "_SoFileFind")
    Global $BtnStart = GUICtrlCreateButton("Start", 293, 220, 75, 25)
    Global $BtnExit = GUICtrlCreateButton("Exit", 406, 220, 75, 25)
    Global $ImageIteam = GUICtrlCreateCombo("Select", 16, 51, 566, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$ES_READONLY))
    ;GUICtrlSetOnEvent($ImageIteam, "ImageIteam")
    Global $Input2 = GUICtrlCreateInput("USB OR RAID Drivers", 16, 165, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $BtnBoot = GUICtrlCreateButton("boot", 507, 126, 75, 25)
    Global $Input3 = GUICtrlCreateInput("boot.wim", 16, 127, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $BtnDrv = GUICtrlCreateButton("Drivers", 507, 164, 75, 25)
    Global $Progress1 = GUICtrlCreateProgress(16, 20, 566, 17)
    Local $iLeft = 8, $iTop = 1, $iWidth = 584, $iHeight = 291, $iColor = 0x142d01, $PanelCol = $GUI_BKCOLOR_TRANSPARENT ; 0xFFFFE0 ;
    _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iColor, $PanelCol) ; Panel - Colouring
    GUISetState(@SW_SHOW)
    _Initial()
    GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Event")
    GUISetOnEvent($BtnExit, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_GUI_Event")
EndFunc   ;==>Example

Func _Initial()
    If Not $DISM_PATH Or Not FileExists($DISM_PATH) Then MsgBox(48, "DISM", "Dism.exe is required.")
EndFunc

Func _SoFileFind()
    Local $sFileOpenDialog = FileOpenDialog("Select Windows Image File", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Windows Image File (*.wim;*.esd)", $FD_FILEMUSTEXIST)
    If @error Then Return SetError(1, 0, 0)
    GUICtrlSetData($BtnSoFileShow, $sFileOpenDialog) ; Set the inputbox with the filepath.
    $MoFile = $sFileOpenDialog
    _GetImageInfo($MoFile)
EndFunc

Func _GetImageInfo($sWimFile)
    Local $DISMp = Run($DISM_PATH & ' /Get-ImageInfo /ImageFile:' & $sWimFile & ' /English','','', $STDOUT_CHILD+$STDERR_CHILD)
    Local $line0, $line1, $line2,$line3
    While ProcessExists($DISMp)
        $line0 = StdoutRead($DISMp)
        If (StringInStr($line0, "Name :")) Then
            $line2 = StringStripWS ( $line0,7)
        EndIf
        ConsoleWrite($line2)
    WEnd

EndFunc


Func _GUI_Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnExit
            GUIDelete($Main)
            Exit
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_MINIMIZE, $Main)
        Case Else
            MsgBox(4096, "Error GUI Event", "UnKnow GUI Event !", 180, 12)
    EndSwitch
EndFunc

Func _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iBorderColor = 0x000000, $iBkGndCol0r = $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateGraphic(-1, -1)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iBorderColor, $iBkGndCol0r)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, $iLeft, $iTop + 8, $iWidth, $iHeight - 7)
EndFunc   ;==>_GuiCtrlGroupSetColor

 

Edited by i2i8
Link to comment
Share on other sites

  • Solution

try this:

#RequireAdmin
#include-once
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
    Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Global $BoFile                                              ; boot.wim Path
Global $MoFile                                              ; install.wim OR install.esd Path
Global $DISM_PATH = @SystemDir & '\Dism.exe'
Global $oDic , $iIndexSelected
    GuiMain()
    While 1
    Sleep(80) ; Sleep to reduce CPU usage
WEnd
    Func GuiMain()
    Global $Main = GUICreate("MosBoot", 600, 300, -1, -1)
    Global $BtnSoFileShow = GUICtrlCreateInput("install.wim Or install.esd", 16, 89, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $Panel = GUICtrlCreateGroup("", 8, 0, 584, 291)
    Global $BtnSoFileFind = GUICtrlCreateButton("install", 507, 88, 75, 25)
    GUICtrlSetOnEvent($BtnSoFileFind, "_SoFileFind")
    Global $BtnStart = GUICtrlCreateButton("Start", 293, 220, 75, 25)
    Global $BtnExit = GUICtrlCreateButton("Exit", 406, 220, 75, 25)
    Global $ImageIteam = GUICtrlCreateCombo("Select", 16, 51, 566, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$ES_READONLY))
    GUICtrlSetOnEvent($ImageIteam, "ImageIteam")
    Global $Input2 = GUICtrlCreateInput("USB OR RAID Drivers", 16, 165, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $BtnBoot = GUICtrlCreateButton("boot", 507, 126, 75, 25)
    Global $Input3 = GUICtrlCreateInput("boot.wim", 16, 127, 465, 21,BitOR($ES_AUTOHSCROLL,$ES_READONLY))
    Global $BtnDrv = GUICtrlCreateButton("Drivers", 507, 164, 75, 25)
    Global $Progress1 = GUICtrlCreateProgress(16, 20, 566, 17)
    Local $iLeft = 8, $iTop = 1, $iWidth = 584, $iHeight = 291, $iColor = 0x142d01, $PanelCol = $GUI_BKCOLOR_TRANSPARENT ; 0xFFFFE0 ;
    _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iColor, $PanelCol) ; Panel - Colouring
    GUISetState(@SW_SHOW)
    _Initial()
    GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Event")
    GUISetOnEvent($BtnExit, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_GUI_Event")
EndFunc   ;==>Example
    Func ImageIteam()
    $iIndexSelected = ""
    Local $sReadCombo = GUICtrlRead($ImageIteam)
    If StringLen($sReadCombo) = 0 Then Return SetError(1,0,'')
    If Not IsObj($oDic) Then Return SetError(2,0,'')
    If Not $oDic.Exists(String(StringToBinary($sReadCombo))) Then Return SetError(3,0,'')
    $iIndexSelected = $oDic.Item(String(StringToBinary($sReadCombo)))
    ConsoleWrite('+ Selected: ' & $iIndexSelected & @CRLF)
EndFunc    
    Func _Initial()
    If Not $DISM_PATH Or Not FileExists($DISM_PATH) Then MsgBox(48, "DISM", "Dism.exe is required.")
EndFunc
    Func _SoFileFind()
    Local $sFileOpenDialog = FileOpenDialog("Select Windows Image File", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Windows Image File (*.wim;*.esd)", $FD_FILEMUSTEXIST)
    If @error Then Return SetError(1, 0, 0)
    GUICtrlSetData($BtnSoFileShow, $sFileOpenDialog) ; Set the inputbox with the filepath.
    $MoFile = $sFileOpenDialog
    _GetImageInfo($MoFile)
EndFunc
    Func _GetImageInfo($sWimFile)
    Local $DISMp = Run($DISM_PATH & ' /Get-ImageInfo /ImageFile:' & $sWimFile & ' /English','','', $STDOUT_CHILD+$STDERR_CHILD)
    Local $sRet , $aRet , $sStrCombo
    While ProcessExists($DISMp)
        $sRet &= StdoutRead($DISMp)
    WEnd
    $oDic = 0
    $oDic = ObjCreate('Scripting.Dictionary')
    $aRet = StringRegExp($sRet,'(?i)Index\h*:\h*(\d+)\s+Name\h*:\h*(\V+)',3)
    If Not @error Then 
        For $i = 0 To UBound($aRet) - 1 Step 2
            $sStrCombo &= '|' &$aRet[$i + 1]
            $oDic.Add(String(StringToBinary($aRet[$i + 1])) , $aRet[$i])
        Next    
        GUICtrlSetData($ImageIteam , $sStrCombo , $aRet[1])
    EndIf    
EndFunc
    
Func _GUI_Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BtnExit
            GUIDelete($Main)
            Exit
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_MINIMIZE, $Main)
        Case Else
            MsgBox(4096, "Error GUI Event", "UnKnow GUI Event !", 180, 12)
    EndSwitch
EndFunc
    Func _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iBorderColor = 0x000000, $iBkGndCol0r = $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateGraphic(-1, -1)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iBorderColor, $iBkGndCol0r)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, $iLeft, $iTop + 8, $iWidth, $iHeight - 7)
EndFunc   ;==>_GuiCtrlGroupSetColor
Edited by Jos
updated codebox to autoit
Link to comment
Share on other sites

3 hours ago, i2i8 said:

I want to extract the index row and the Name row

You might build a 2D array

$txt = "PS C:\> Dism /Get-ImageInfo /ImageFile:H:\sources\install.wim /English /Format:Table" & @crlf & _ 
    @crlf & _ 
    "Deployment Image Servicing and Management tool" & @crlf & _ 
    "Version: 10.0.19041.844" & @crlf & _ 
    @crlf & _ 
    "Details for image : H:\sources\install.wim" & @crlf & _ 
    @crlf & _ 
    "Index : 1" & @crlf & _ 
    "Name : Windows Server 2016 Standard" & @crlf & _ 
    "Description : This option (recommended) reduces management and servicing by installing only what is needed to run most server roles and applications. It does not include a GUI, but you can fully manage the server locally or remotely with Windows PowerShell or other tools. For more details see ""Windows Server Installation Options.""" & @crlf & _ 
    "Size : 9,180,501,839 bytes" & @crlf & _ 
    @crlf & _ 
    "Index : 2" & @crlf & _ 
    "Name : Windows Server 2016 Standard (Desktop Experience)" & @crlf & _ 
    "Description : This option is useful when a GUI is required—for example, to provide backward compatibility for an application that cannot be run on a Server Core installation. All server roles and features are supported. For more details see ""Windows Server Installation Options.""" & @crlf & _ 
    "Size : 15,196,490,590 bytes" & @crlf & _ 
    @crlf & _ 
    "Index : 3" & @crlf & _ 
    "Name : Windows Server 2016 Datacenter" & @crlf & _ 
    "Description : This option (recommended) reduces management and servicing by installing only what is needed to run most server roles and applications. It does not include a GUI, but you can fully manage the server locally or remotely with Windows PowerShell or other tools. For more details see ""Windows Server Installation Options.""" & @crlf & _ 
    "Size : 9,175,696,563 bytes" & @crlf & _ 
    @crlf & _ 
    "Index : 4" & @crlf & _ 
    "Name : Windows Server 2016 Datacenter (Desktop Experience)" & @crlf & _ 
    "Description : This option is useful when a GUI is required—for example, to provide backward compatibility for an application that cannot be run on a Server Core installation. All server roles and features are supported. For more details see ""Windows Server Installation Options.""" & @crlf & _ 
    "Size : 15,198,865,664 bytes" & @crlf & _ 
    @crlf & _ 
    "The operation completed successfully."
; Msgbox(0,"", $txt)

#Include <Array.au3>
;$txt = ClipGet()
$a = StringRegExp($txt, 'Index : (\d+)\RName : (\N+)', 3)
Local $res[UBound($a)/2][2]
For $i = 0 to UBound($res)-1 
   $res[$i][0] = $a[$i*2]
   $res[$i][1] = $a[$i*2+1]
Next
_ArrayDisplay($res)

 

Link to comment
Share on other sites

@AllenAA

I would like your help with another question. As for the GUI above, after I click the Exit button, the exit event does not take effect, and the entire GUI cannot exit without any reaction. Could you please help me see what went wrong?

Link to comment
Share on other sites

33 minutes ago, i2i8 said:

@AllenAA

I would like your help with another question. As for the GUI above, after I click the Exit button, the exit event does not take effect, and the entire GUI cannot exit without any reaction. Could you please help me see what went wrong?

There is a difference between GUICtrlSetOnEvent and GUISetOnEvent.

#RequireAdmin
#include-once
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Global $BoFile ; boot.wim Path
Global $MoFile ; install.wim OR install.esd Path
Global $DISM_PATH = @SystemDir & '\Dism.exe'
Global $oDic, $iIndexSelected
GuiMain()
While 1
    Sleep(80) ; Sleep to reduce CPU usage
WEnd
Func GuiMain()
    Global $Main = GUICreate("MosBoot", 600, 300, -1, -1)
    Global $BtnSoFileShow = GUICtrlCreateInput("install.wim Or install.esd", 16, 89, 465, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
    Global $Panel = GUICtrlCreateGroup("", 8, 0, 584, 291)
    Global $BtnSoFileFind = GUICtrlCreateButton("install", 507, 88, 75, 25)
    GUICtrlSetOnEvent($BtnSoFileFind, "_SoFileFind")
    Global $BtnStart = GUICtrlCreateButton("Start", 293, 220, 75, 25)
    Global $BtnExit = GUICtrlCreateButton("Exit", 406, 220, 75, 25)
    GUICtrlSetOnEvent(-1, "_Exit"); <<
    Global $ImageIteam = GUICtrlCreateCombo("Select", 16, 51, 566, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $ES_READONLY))
    GUICtrlSetOnEvent($ImageIteam, "ImageIteam")
    Global $Input2 = GUICtrlCreateInput("USB OR RAID Drivers", 16, 165, 465, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
    Global $BtnBoot = GUICtrlCreateButton("boot", 507, 126, 75, 25)
    Global $Input3 = GUICtrlCreateInput("boot.wim", 16, 127, 465, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
    Global $BtnDrv = GUICtrlCreateButton("Drivers", 507, 164, 75, 25)
    Global $Progress1 = GUICtrlCreateProgress(16, 20, 566, 17)
    Local $iLeft = 8, $iTop = 1, $iWidth = 584, $iHeight = 291, $iColor = 0x142d01, $PanelCol = $GUI_BKCOLOR_TRANSPARENT ; 0xFFFFE0 ;
    _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iColor, $PanelCol) ; Panel - Colouring
    GUISetState(@SW_SHOW)
    _Initial()
    GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Event")
    ;GUISetOnEvent($BtnExit, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GUI_Event")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_GUI_Event")
EndFunc   ;==>GuiMain
Func ImageIteam()
    $iIndexSelected = ""
    Local $sReadCombo = GUICtrlRead($ImageIteam)
    If StringLen($sReadCombo) = 0 Then Return SetError(1, 0, '')
    If Not IsObj($oDic) Then Return SetError(2, 0, '')
    If Not $oDic.Exists(String(StringToBinary($sReadCombo))) Then Return SetError(3, 0, '')
    $iIndexSelected = $oDic.Item(String(StringToBinary($sReadCombo)))
    ConsoleWrite('+ Selected: ' & $iIndexSelected & @CRLF)
EndFunc   ;==>ImageIteam
Func _Initial()
    If Not $DISM_PATH Or Not FileExists($DISM_PATH) Then MsgBox(48, "DISM", "Dism.exe is required.")
EndFunc   ;==>_Initial
Func _SoFileFind()
    Local $sFileOpenDialog = FileOpenDialog("Select Windows Image File", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Windows Image File (*.wim;*.esd)", $FD_FILEMUSTEXIST)
    If @error Then Return SetError(1, 0, 0)
    GUICtrlSetData($BtnSoFileShow, $sFileOpenDialog) ; Set the inputbox with the filepath.
    $MoFile = $sFileOpenDialog
    _GetImageInfo($MoFile)
EndFunc   ;==>_SoFileFind
Func _GetImageInfo($sWimFile)
    Local $DISMp = Run($DISM_PATH & ' /Get-ImageInfo /ImageFile:' & $sWimFile & ' /English', '', '', $STDOUT_CHILD + $STDERR_CHILD)
    Local $sRet, $aRet, $sStrCombo
    While ProcessExists($DISMp)
        $sRet &= StdoutRead($DISMp)
    WEnd
    $oDic = 0
    $oDic = ObjCreate('Scripting.Dictionary')
    $aRet = StringRegExp($sRet, '(?i)Index\h*:\h*(\d+)\s+Name\h*:\h*(\V+)', 3)
    If Not @error Then
        For $i = 0 To UBound($aRet) - 1 Step 2
            $sStrCombo &= '|' & $aRet[$i + 1]
            $oDic.Add(String(StringToBinary($aRet[$i + 1])), $aRet[$i])
        Next
        GUICtrlSetData($ImageIteam, $sStrCombo, $aRet[1])
    EndIf
EndFunc   ;==>_GetImageInfo
    Func _GUI_Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
;~         Case $BtnExit
;~             GUIDelete($Main)
;~             Exit
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_MINIMIZE, $Main)
        Case Else
            MsgBox(4096, "Error GUI Event", "UnKnow GUI Event !", 180, 12)
    EndSwitch
EndFunc   ;==>_GUI_Event
Func _GuiCtrlGroupSetColor($iLeft, $iTop, $iWidth, $iHeight, $iBorderColor = 0x000000, $iBkGndCol0r = $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateGraphic(-1, -1)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iBorderColor, $iBkGndCol0r)
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, $iLeft, $iTop + 8, $iWidth, $iHeight - 7)
EndFunc   ;==>_GuiCtrlGroupSetColor
Func _Exit()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit
 

Edited by AllenAA
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...