mdwerne,
I might do it like this...
; script requires 3.3.10+
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
_create_test_file()
Local $gui010 = GUICreate('BitLocker Key Test', 600, 200)
Local $sRecoveryKey = GUICtrlCreateCombo('', 20, 20, 330, 100, $cbs_dropdownlist)
_GUICtrlComboBox_SetCueBanner($sRecoveryKey, "Select a Recovery Key")
GUICtrlSetData($sRecoveryKey, GetKey())
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $sRecoveryKey
ConsoleWrite('Recovery key selected = ' & GUICtrlRead($sRecoveryKey) & @LF)
EndSwitch
WEnd
Func GetKey()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Local Const $sMessage = "Select the BitLocker Key File."
; Display an open dialog to select a file.
Local $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "Bitlocker Key File (*.txt)", $FD_FILEMUSTEXIST)
If @error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
EndIf
Local $ret = StringRegExp(FileRead($sFileOpenDialog), '(?:\d{6}-){7}\d{6}', 3), $tstr
Switch @error
Case 0
For $1 = 0 To UBound($ret) - 1
$tstr &= '|' & $ret[$1]
Next
Return $tstr
Case 1
ConsoleWrite('No matches' & @LF)
Exit
Case 2
ConsoleWrite('Bad pattern at offset ' & @extended & @LF)
Exit
EndSwitch
EndFunc ;==>GetKey
; -----------------------------------------------------------------------------------------------------------------------------
;
; functions used to create test file
;
; -----------------------------------------------------------------------------------------------------------------------------
Func _create_test_file()
Local $str, $FilePath = @ScriptDir & '\bitlocker.txt'
For $1 = 1 To 10
For $2 = 1 To 5
$str &= (Mod($2, 2) = 0) ? _garbage() : _bitlockerpattern()
Next
Next
FileDelete($FilePath)
FileWrite($FilePath, $str)
EndFunc ;==>_create_test_file
Func _garbage()
Local $tstr = ''
For $1 = 1 To Random(1, 50, 1)
$tstr &= Chr(Random(1, 256, 1))
Next
Return $tstr
EndFunc ;==>_garbage
Func _bitlockerpattern()
Local $tstr = ''
For $1 = 1 To 8
For $2 = 1 To 6
$tstr &= Random(0, 9, 1)
Next
$tstr &= '-'
Next
Return $tstr
EndFunc ;==>_bitlockerpattern
The gui is rough and proof of concept only.
I dreamed up a test file consisting of junk with valid keys interspersed throughout since you did not provide an example.
kylomas