This is more or less what I do in AutoIt3Wrapper to detect the different BOM options and later strip the inputfile, and later add it back.
Local $hTest_UTF = FileOpen("filename", 16)
Local $Test_UTF = FileRead($hTest_UTF, 4)
Local $i_Rec_Param, $i_Rec_Value, $Temp_Val
FileClose($hTest_UTF)
;~ 00 00 FE FF UTF-32, big-endian
;~ FF FE 00 00 UTF-32, little-endian
;~ FE FF UTF-16, big-endian
;~ FF FE UTF-16, little-endian
;~ EF BB BF UTF-8
Select
Case BinaryMid($Test_UTF, 1, 4) = '0x0000FEFF' ; UTF-32 BE
$UTFtype = '32BE'
Case BinaryMid($Test_UTF, 1, 4) = '0xFFFE0000' ; UTF-32 LE
$UTFtype = '32LE'
Case BinaryMid($Test_UTF, 1, 2) = '0xFEFF' ; UTF-16 BE
$UTFtype = '16BE'
Case BinaryMid($Test_UTF, 1, 2) = '0xFFFE' ; UTF-16 LE
$UTFtype = '16LE'
Case BinaryMid($Test_UTF, 1, 3) = '0xEFBBBF' ; UTF-8
$UTFtype = '8'
Case Else
$UTFtype = ''
EndSelect
Jos