There is indeed a problem with the capture of Boot.tmp for you.
Strange, no problem with mount/unmount, just with the /capture switch !
difficult to know from where come the exitcode 2, it can come from an agressive AV. Well to try to exclude the project folder in your AV.
In postconfig script, not to let him continue in this case and removing Boot.tmp, you can change that part of code with this.
If,%WimTools%,Equal,ImageX,Begin
If,%pCompressionGroup%,Equal,0,ShellExecute,%ShowImageX%,%IMAGEX%,"/capture #$q%BootTMP%#$q #$q%TargetDir%sourcesboot.wim#$q #$qWin7PE#$q /boot"
If,%pCompressionGroup%,Equal,1,ShellExecute,%ShowImageX%,%IMAGEX%,"/capture #$q%BootTMP%#$q #$q%TargetDir%sourcesboot.wim#$q #$qWin7PE#$q /boot /compress maximum"
Echo,"%WimTools% Packing boot.wim return : %ExitCode%"
If,Not,%ExitCode%,Equal,0,Run,%scriptfile%,ErrorPack,boot.wim
End
If,%WimTools%,Equal,WimUtil,Begin
If,%pCompressionGroup%,Equal,0,ShellExecute,Hide,%WIMUTIL%,"/capture #$q%BootTMP%#$q #$q%TargetDir%sourcesboot.wim#$q #$qWin7PE#$q /boot /xpress %ShowWimUtil%"
If,%pCompressionGroup%,Equal,1,ShellExecute,Hide,%WIMUTIL%,"/capture #$q%BootTMP%#$q #$q%TargetDir%sourcesboot.wim#$q #$qWin7PE#$q /boot /lzx %ShowWimUtil%"
Echo,"%WimTools% Packing boot.wim return : %ExitCode%"
If,Not,%ExitCode%,Equal,0,Run,%scriptfile%,ErrorPack,boot.wim
End
//--
DirDelete,"%BootTMP%"
[ErrorPack]
Message,"A problem occurred to Pack #1 with %WimTools% return Code : %ExitCode% !!!#$x#$xExiting..."
Halt,"A problem occurred to Pack #1 with %WimTools% return Code : %ExitCode%. Exiting..."
If the error persists try manually imagex /capture in cmdline (you can do also, a test with an other folder ).
Edit: you can also try by choosing WimUtil in "image configuration", it produces a wimutil.log in %temp% directory, Perhaps more expressive than imagex return 2.
WimUtil.exe /Capture "image_path" "image_file" "image_name" /boot /xpress