Jump to content

Copy issues with x64 binary on Win10/11 hosts, x86 is working fine.


bobomb
 Share

Recommended Posts

 

EDIT: I just found this issue reported in the copy UDF thread as well. It seems archived at this point.. Is anyone able to look at the pointer call to see if this is the DLL or not?

Same program I was getting help with (BurnTool) GUI, Progress etc.. But this issue is unrelated, only the program itself is the same, so I thought it prudent to open a thread for this specific issue..

As the title states, I can compile this as x86 and it works fine.. Once compiled x64 the copy GUI opens and then crashes before anything starts to copy.. (Works x64 on Win7 but NOT on Win10 or Win11)

This uses @Yashied's Copy UDF: https://www.autoitscript.com/forum/topic/121833-copy-udf/ (This is where the DLL's and UDF came from but if you dont want to use what I provided in the 7z you can get them yourself they are located here)

Copy.dll is present for x86 during execution...

Copy_x64.dll is present for x64 during execution...

Subfolder Copy\Images\ is used for simple GUI...

A 7z is attached with test files and a test ISO. The TestISO.ISO file appears to contain data however ALL files with the exception of the autorun.ico file are really just TEXT files filled with the words testtesttest repeatedly.. So bootmgr.exe is a renamed text file you can see with a text editor or by renaming it back. This is done for the purpose of not pissing off MS (or anyone else ;)) and still having something to test with for anyone willing to help.. 

If you are going to try and Run the software this is a USB or Fixed drive burning tool.. Be aware that it does format drives you tell it to, and then it copies files from the ISO to the USB/Fixed drive you choose. You will need a blank USB to test (or one you are willing to format).

If you drop the extracted files into C:\bobomb\ you will not have to alter the code to run the initial x86 vs x64 testing (paths are hardcoded for copy UDF and GUI files) ..

Script posted for visibility but included in the attached 7z

#NoTrayIcon
#RequireAdmin

#Tidy_Parameters=/sf

#Region #### autoit udfs ####
#include <Array.au3>
#include <ColorConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WinAPIFiles.au3>
#include <WinAPIInternals.au3>
#include <WindowsConstants.au3>
#EndRegion #### autoit udfs ####

#Region #### user udfs ####
#include 'C:\Bobomb\Copy\UDF\Copy.au3'
#EndRegion #### user udfs ####

#Region #### globals ####
Global Const _ ; GUI_SwitchGUI
        $GA_DELETEOLDGUINO = 0, _
        $GA_DELETEOLDGUIYES = 1, _
        $GA_DISABLEOLDGUINO = 0, _
        $GA_DISABLEOLDGUIYES = 1, _
        $GA_HIDEOLDGUINO = 0, _
        $GA_HIDEOLDGUIYES = 1, _
        $GA_ONEVENTMODENO = 0, _
        $GA_ONEVENTMODEYES = 1

Global $h_MainGUI = 0 ; main gui for GUI_SwitchGUI function

Global _
        $id_DiskList = 0, _
        $id_BurnBtn = 0
Global _
        $s_BootDrive = '', _
        $s_DataDrive = '', _
        $s_MountedDrive = ''
#EndRegion #### globals ####

Opt("GUIOnEventMode", 1)

Initialise() ; _    run program pre checks
GUI_CreateGUI() ; _ create the main program gui

Func BootWim_Check() ; check for the boot wim file
    If Not FileExists($s_MountedDrive & '\sources\boot.wim') Then
        MsgBox( _
                $MB_ICONERROR, _
                "Notice: ", _
                "BOOT.WIM NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.")

        GUI_CloseGUI()
    EndIf
EndFunc   ;==>BootWim_Check

Func BootWim_GetSize() ; get the boot wim size and add 200 megabytes for headroom on boot partition
    Return Round((FileGetSize($s_MountedDrive & '\sources\boot.wim') + 209715200) / 1048576)
EndFunc   ;==>BootWim_GetSize

Func BurnPressed() ; start the burn process
    Local $s_DiskNumber = StringRegExp(GUICtrlRead($id_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)

    If $s_DiskNumber = "" Then
        MsgBox( _
                $MB_ICONERROR, _ ; it is possible to bug the GUI and make the buttons appear by pressing + or - on tree then refresh
                "Attention: ", _
                "No disk is selected!")
        Buttons_Disable()
    Else

        Local $s_DiskNumber = StringRegExp(GUICtrlRead($id_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0]

        If @error Then
            MsgBox( _
                    $MB_ICONERROR, _
                    "Notice: ", _
                    "An error occured retrieving the disk number")
        Else
            If MsgBox( _
                    BitOR($MB_TOPMOST, $MB_ICONWARNING, $MB_YESNO, $MB_DEFBUTTON2), _
                    'This will FORMAT Disk ' & $s_DiskNumber, _
                    'ALL DATA WILL BE ERASED FROM DISK ' & $s_DiskNumber & @CRLF & 'Are you sure you want to proceed?') = $IDYES Then
                GUISetState(@SW_HIDE)
                ProgressOn("BurnTool (XPE/SE) v2.0", "Creating Bootable Media...", "0%")
                Format_Prepare($s_DiskNumber)
                ProgressSet(5 & "%", "Formatting Disk " & $s_DiskNumber)
                Format_Run()
                ProgressSet(100, "Format Complete", "Begin Filecopy...")
                ProgressOff()
                MsgBox(1, "", $s_MountedDrive & "  -  " & $s_BootDrive & ':')
                Copy_PartitionFiles($s_MountedDrive, $s_BootDrive & ':')
                Copy_PartitionFiles($s_MountedDrive, $s_DataDrive & ':', "Data")

                MsgBox( _
                        $MB_ICONINFORMATION, _
                        "Process Complete", _
                        " Enjoy! ")

                GUI_CloseGUI()
            EndIf
        EndIf
    EndIf
EndFunc   ;==>BurnPressed

Func Buttons_Disable() ; disable the gui buttons
    GUICtrlSetState($id_BurnBtn, $GUI_DISABLE)
EndFunc   ;==>Buttons_Disable

Func Buttons_Enable() ; enable the gui buttons
    GUICtrlSetState($id_BurnBtn, $GUI_ENABLE)
EndFunc   ;==>Buttons_Enable

Func CacheFolder_DeleteFiles() ; remove the cache folder and exit program if specified
    If FileExists(CacheFolder_GetPath()) Then DirRemove(CacheFolder_GetPath(), $DIR_REMOVE)
EndFunc   ;==>CacheFolder_DeleteFiles

Func CacheFolder_GetPath() ; get the path to the cache folder, returns with trailing '\'
    Local Static $s_CachePath = IniRead(@WorkingDir & '\USBTool.ini', "Settings", "CachePath", @WorkingDir & '\cache') & '\'
    Return $s_CachePath
EndFunc   ;==>CacheFolder_GetPath

Func Copy_FilesFolders($s_Title, ByRef $as_Files, $s_Source, $s_Destination, $h_OldGui, $b_RemoveRO = False) ; copy the required files to the selected partition
    Local _
            $i_Error = 0, _
            $i_Extended = 0

    Local $v_Return = ''

    If $s_Source <> '' And $s_Destination <> '' Then
        ; check for an array of files and folders
        If IsArray($as_Files) Then
            $s_Destination = StringRegExpReplace($s_Destination, '\\+$', '')

            ; check for destinaation and create if missing
            If Not FileExists($s_Destination) Then DirCreate($s_Destination)

            ; check if the destination exists
            If FileExists($s_Destination) Then
                ; make sure there's no trailing '\' then add one
                $s_Source = StringRegExpReplace($s_Source, '\\+$', '') & '\'
                $s_Destination = StringRegExpReplace($s_Destination, '\\+$', '') & '\'

                ; the dll file(s) need to be in the same dir as the script.
                ; if you dont want this, then use fileinstall to install it
                ; where you have write access x64 = Copy_x64.dll, x86 = Copy.dll
                If _Copy_OpenDll() Then
                    #Region #### create gui ####
                    Local _
                            $i_FontSize = 16, _
                            $i_FontWeight = 800, _
                            $i_PbarWidth = 400
                    Local _
                            $s_FontName = 'Trebuchet MS', _
                            $s_FontColour = $COLOR_WHITE, _
                            $s_BkColour = $GUI_BKCOLOR_TRANSPARENT

                    Local $h_CopyGUI = GUICreate('Copy GUI', 634, 176, 1344, 367, $WS_POPUP, $WS_EX_LAYERED)
                    GUICtrlCreatePic('C:\Bobomb\Copy\Images\GUIBack.bmp', 0, 0, 633, 175)
                    GUICtrlSetState(-1, $GUI_DISABLE)

                    GUICtrlCreatePic('C:\Bobomb\Copy\Images\GUIBanner.bmp', 0, 0, 633, 32)
                    GUICtrlSetState(-1, $GUI_DISABLE)

                    GUICtrlCreateLabel($s_Title, 5, 5, 561, 25)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    $i_FontSize = 10
                    $s_FontName = 'MS Sans Serif'

                    GUICtrlCreateLabel('Source       :', 10, 45, 85, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    Local $id_Source_lbl = GUICtrlCreateLabel('', 100, 45, 520, 17, $DT_END_ELLIPSIS)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    GUICtrlCreateLabel('Destination:', 10, 69, 85, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    Local $id_Destination_lbl = GUICtrlCreateLabel('', 100, 69, 520, 17, $DT_END_ELLIPSIS)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    $i_FontSize = 8

                    Local $id_Action_lbl = GUICtrlCreateLabel('', 72, 110, 72, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    Local $id_Info_lbl = GUICtrlCreateLabel('', 148, 110, 335, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    GUICtrlCreateLabel('File', 72, 129, 35, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_PbarBack.bmp', 115, 130, 403, 14)
                    GUICtrlSetState(-1, $GUI_DISABLE)

                    Local $id_CopyProgBar = GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_Pbar.bmp', 116, 133, 1, 8)

                    Local $id_FileSize_lbl = GUICtrlCreateLabel('23', 522, 129, 100, 14)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    GUICtrlCreateLabel('Total', 72, 149, 35, 17)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_PbarBack.bmp', 115, 150, 403, 14)
                    GUICtrlSetState(-1, $GUI_DISABLE)

                    Local $id_totalProgBar = GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_Pbar.bmp', 116, 153, 1, 8)

                    Local $id_TotalFileCount_lbl = GUICtrlCreateLabel('0/' & $as_Files[0], 522, 150, 100, 14)
                    GUICtrlSetBkColor(-1, $s_BkColour)
                    GUICtrlSetColor(-1, $s_FontColour)
                    GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName)

                    ; set the GUI transparency
                    ;_WinAPI_SetLayeredWindowAttributes($h_CopyGUI, 0x010101, 200)
                    #EndRegion #### create gui ####

                    ; change the gui
                    GUI_SwitchGUI($h_CopyGUI, $h_OldGui, Default, $GA_DISABLEOLDGUIYES, $GA_HIDEOLDGUIYES)
                    GUI_CentreGUI($h_OldGui, $h_CopyGUI)
                    GUISetState(@SW_SHOW, $h_CopyGUI)

                    Local $ai_State = 0

                    ; loop through the files and copy them
                    For $i = 1 To $as_Files[0]
                        ; check if file or dir and change copy mode
                        If _WinAPI_PathIsDirectory($s_Source & $as_Files[$i]) Then
                            _Copy_CopyDir($s_Source & $as_Files[$i], $s_Destination & $as_Files[$i], $COPY_FILE_NO_BUFFERING, $COPY_OVERWRITE_YES)
                        Else
                            _Copy_CopyFile($s_Source & $as_Files[$i], $s_Destination & $as_Files[$i], $COPY_FILE_NO_BUFFERING)
                        EndIf

                        GUICtrlSetData($id_Action_lbl, Copy_GetStatus()) ; status

                        While 1
                            $ai_State = _Copy_GetState()

                            If $ai_State[0] Then
                                If GUICtrlRead($id_Source_lbl) <> $ai_State[6] Then GUICtrlSetData($id_Source_lbl, $ai_State[6])
                                If GUICtrlRead($id_Destination_lbl) <> $ai_State[7] Then GUICtrlSetData($id_Destination_lbl, $ai_State[7])
                                Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar, $ai_State[3], $ai_State[4]) ; file copy progress bar
                                GUICtrlSetData($id_FileSize_lbl, _WinAPI_StrFormatByteSize($ai_State[3]) & '/' & _WinAPI_StrFormatByteSize($ai_State[4])) ; file copy transferred
                            Else
                                Switch $ai_State[5]
                                    Case 0 ; all OK

                                    Case 1235 ; ERROR_REQUEST_ABORTED
;~
                                    Case Else ; add the error file\dir and error code to the array
                                        $i_Error = 7
                                        $i_Extended += 1
                                        Copy_UpdateErrorArray($ai_State[6], $ai_State[5])
                                EndSwitch

                                Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar, 100, 100) ; _           set file copy progress bar
                                Copy_SetTotalProgress($h_CopyGUI, $id_totalProgBar, $i, $as_Files[0]) ;_  set total progress bar
                                GUICtrlSetData($id_TotalFileCount_lbl, $i & '/' & $as_Files[0]) ;         set total copy count

                                ExitLoop
                            EndIf

                            Sleep(80)
                        WEnd
                    Next

                    ; reset the controls
                    GUICtrlSetData($id_Source_lbl, '')
                    GUICtrlSetData($id_Destination_lbl, '')
                    GUICtrlSetData($id_Action_lbl, '')
                    Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar)
                    Copy_SetFileProgress($h_CopyGUI, $id_totalProgBar)
                    GUICtrlSetData($id_FileSize_lbl, '')
                    GUICtrlSetData($id_TotalFileCount_lbl, '')

                    If $b_RemoveRO Then ; remove read only attributes from the destination
                        GUICtrlSetData($id_Action_lbl, 'Removing')
                        GUICtrlSetData($id_Info_lbl, 'Read Only attributes on ' & $s_Destination)
                        FileSetAttrib($s_Destination, '-R', $FT_RECURSIVE)
                    EndIf

                    GUI_SwitchGUI($h_OldGui, $h_CopyGUI, Default, Default, $GA_DELETEOLDGUIYES)

                    If Not _Copy_CloseDll() Then ; error closing the copy dll
                        $i_Error = 6
                        $v_Return = 'Unable to close the dll file: ' & Copy_GetDllName()
                    EndIf
                Else ; unable to open copy dll
                    $i_Error = 4
                    $v_Return = 'Unable to find the dll file: ' & Copy_GetDllName()
                EndIf
            Else ; unable to create destination
                $i_Error = 3
                $v_Return = 'Unable to create destination: ' & $s_Destination
            EndIf
        Else ; array not valid
            $i_Error = 2
            $v_Return = '$as_Files is not an array. No files\folders to copy'
        EndIf
    Else
        $i_Error = 1
        $v_Return = 'Missing Source or Destination values'
    EndIf

    Return SetError($i_Error, $i_Extended, $v_Return)
EndFunc   ;==>Copy_FilesFolders

Func Copy_GetDllName() ; get the dll name for Copy_FilesFolders
    Return (@AutoItX64 = 0) ? ('Copy.dll') : ('Copy_x64.dll')
EndFunc   ;==>Copy_GetDllName

Func Copy_GetStatus() ; get the file\folder current action for Copy_FilesFolders
    Return (_Copy_GetAction() = 0) ? ('Copying File') : ('Moving File')
EndFunc   ;==>Copy_GetStatus

Func Copy_PartitionFiles($s_Source, $s_Destination, $s_Partition = 'Boot') ; set the required files and partition for Copy_FilesFolders
    Local $s_BootList = 'boot;efi;sources;bootmgr;bootmgr.efi;bootmgr.exe;menu.lst'
    Local $s_Mask = $s_BootList

    If $s_Partition = 'Data' Then $s_Mask = '*|' & $s_BootList

    ; search the source for specified files only
    Local $as_Files = _FileListToArrayRec($s_Source, $s_Mask, $FLTAR_FILESFOLDERS, $FLTAR_NORECUR, $FLTAR_SORT)

    Local $v_Ret = Copy_FilesFolders('Copying ' & $s_Partition & ' Files', $as_Files, $s_Source, $s_Destination, $h_MainGUI)

    If @error Then
        If @extended Then
            If MsgBox( _
                    BitOR($MB_ICONERROR, $MB_YESNO, $MB_DEFBUTTON2), _
                    'Copy Error(s): ' & @extended, _
                    'Error(s) Occurred during the copy process ' & @CRLF & ' Do you want to view the file names?') = $IDYES Then _
                    _ArrayDisplay(Copy_UpdateErrorArray(), 'Copy Errors', '', $ARRAYDISPLAY_COLALIGNLEFT, Default, 'Path|ErrorCode')
        Else
            MsgBox( _
                    $MB_ICONERROR, _
                    'Error occured', _
                    $v_Ret)
        EndIf
    Else
        MsgBox( _
                $MB_ICONINFORMATION, _
                $s_Partition  & ' Partition', _
                'All ' & $s_Partition & ' files were successfully copied to :- ' & @CRLF & $s_Destination)
    EndIf
EndFunc   ;==>Copy_PartitionFiles

Func Copy_SetFileProgress($h_Gui, $id_Ctrl, $i_Current = 0, $i_Total = 0) ; set the file copy progress bar for Copy_FilesFolders
    Local $ai_Pos = ControlGetPos($h_Gui, '', $id_Ctrl)
    Local $i_Value = 0

    If $i_Current <> 0 Then $i_Value = (Round($i_Current / $i_Total * 100) * 4)

    GUICtrlSetPos($id_Ctrl, $ai_Pos[0], $ai_Pos[1], $i_Value, $ai_Pos[3])
EndFunc   ;==>Copy_SetFileProgress

Func Copy_SetTotalProgress($h_Gui, $id_Ctrl, $i_Current = 0, $i_Total = 0) ; set the total progress bar for Copy_FilesFolders
    Local $ai_Pos = ControlGetPos($h_Gui, '', $id_Ctrl)
    Local $i_Value = 0

    If $i_Current <> 0 Then $i_Value = (Round($i_Current / $i_Total * 100) * 4)

    GUICtrlSetPos($id_Ctrl, $ai_Pos[0], $ai_Pos[1], $i_Value, $ai_Pos[3])
EndFunc   ;==>Copy_SetTotalProgress

Func Copy_UpdateErrorArray($s_Path = '', $i_ErrorCode = 0)
    Local Static $as_Error[1][2] = [[0, '']]

    If $s_Path <> '' Then
        $as_Error[0][0] = _ArrayAdd($as_Error, $s_Path & '|' & _WinAPI_GetErrorMessage($i_ErrorCode))
    Else
        Return $as_Error
    EndIf
EndFunc   ;==>Copy_UpdateErrorArray

Func DiskList_GetDrives() ; get the system drives
    Local Const $WBEMFLAGRETURNIMMEDIATELY = 0x10

    Local Enum _
            $Unknown, _
            $NoRootDirectory, _
            $RemovableDisk, _
            $LocalDisk, _
            $NetworkDrive, _
            $CompactDisk, _
            $RAMDisk

    Local $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

    If IsObj($o_WMIService) Then
        Local $s_Query = "SELECT * FROM Win32_DiskDrive"
        Local $o_DiskDrives = $o_WMIService.ExecQuery($s_Query, "WQL", $WBEMFLAGRETURNIMMEDIATELY)

        If IsObj($o_DiskDrives) Then
            Local $o_Partitions = 0
            Local $o_LogicalDisks = 0

            For $o_DiskDrive In $o_DiskDrives
                $h_Parent = GUICtrlCreateTreeViewItem("Disk " & $o_DiskDrive.Index & " [" & $o_DiskDrive.Model & "]", $id_DiskList)
                GUICtrlSetOnEvent(-1, 'Buttons_Enable')
                _GUICtrlTreeView_SetIcon($id_DiskList, $h_Parent, "shell32.dll", 15)

                $s_Query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $o_DiskDrive.DeviceId & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
                $o_Partitions = $o_WMIService.ExecQuery($s_Query)

                If IsObj($o_Partitions) Then
                    For $o_Partition In $o_Partitions
                        $s_Query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $o_Partition.DeviceId & "'} WHERE AssocClass = Win32_LogicalDiskToPartition"
                        $o_LogicalDisks = $o_WMIService.ExecQuery($s_Query)

                        For $o_LogicalDisk In $o_LogicalDisks
                            If $o_LogicalDisk.drivetype = $RemovableDisk Or $o_LogicalDisk.drivetype = $LocalDisk Then
                                GUICtrlCreateTreeViewItem('(' & $o_LogicalDisk.DeviceId & '\) ' & $o_LogicalDisk.Volumename, $h_Parent)
                                GUICtrlSetOnEvent(-1, 'Buttons_Disable')
                                _GUICtrlTreeView_SetIcon($id_DiskList, -1, "shell32.dll", 7)
                            EndIf
                        Next
                    Next
                Else
                    ; add error info here
                EndIf
            Next
        Else
            ; add error info here
        EndIf
    Else
        ; add error info here
    EndIf
EndFunc   ;==>DiskList_GetDrives

Func DiskList_Load() ; load the system drives
    _GUICtrlTreeView_BeginUpdate($id_DiskList)
    _GUICtrlTreeView_DeleteAll($id_DiskList)
    DiskList_GetDrives()
    If _GUICtrlTreeView_GetCount($id_DiskList) > 2 Then _GUICtrlTreeView_Sort($id_DiskList)
    _GUICtrlTreeView_Expand($id_DiskList)
    _GUICtrlTreeView_EndUpdate($id_DiskList)
    Buttons_Disable()
EndFunc   ;==>DiskList_Load

Func Diskpart_CreateScriptFile($s_File, $s_Data) ; create the diskpart script file
    Local $h_CacheFile = FileOpen(CacheFolder_GetPath() & $s_File, $FO_OVERWRITE)

    FileWrite($h_CacheFile, $s_Data)
    FileClose($h_CacheFile)
EndFunc   ;==>Diskpart_CreateScriptFile

Func DriveLetters_GetAvailable() ; get the available system drive letters
    Local $as_DriveList = DriveGetDrive($DT_ALL)
    Local _
            $s_DriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ", _
            $s_AvailableDriveLetters

    If @error Then ; An error occurred when retrieving the drives.
        MsgBox( _
                BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), _
                "", _
                "An Error Occurred! Unable to retrieve available drive letters! Exiting Program...")

        GUI_CloseGUI()
    Else ; loop through the enumerated drives and remove those in use
        Local $s_DriveLetter = ''

        For $i = 1 To $as_DriveList[0]
            $s_DriveLetter = StringLeft(StringUpper($as_DriveList[$i]), 1)
            $s_DriveLetters = StringReplace($s_DriveLetters, $s_DriveLetter, "")
        Next
    EndIf

    ; get an array of available drive letters
    $s_AvailableDriveLetters = StringSplit($s_DriveLetters, "")

    $s_BootDrive = $s_AvailableDriveLetters[1] ; Get first available letter (returns without ':\', needed for DiskPart assign letter)
    $s_DataDrive = $s_AvailableDriveLetters[2] ; Get second available letter (returns without ':\', needed for DiskPart assign letter)
    ;$s_DataDrive = $s_AvailableDriveLetters[1] ; Get second available letter
EndFunc   ;==>DriveLetters_GetAvailable

Func Format_Prepare($s_Drive) ; prepare the diskpart script files
    DriveLetters_GetAvailable()
    Diskpart_CreateScriptFile('clean.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'clean' & @CRLF & 'Exit')
    Diskpart_CreateScriptFile('attrib.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit')
    Diskpart_CreateScriptFile('scrubber.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=scrubber' & @CRLF & 'Exit')
    Diskpart_CreateScriptFile('convert.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'convert mbr' & @CRLF & 'Exit')
    Diskpart_CreateScriptFile('initdata.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'shrink minimum=' & BootWim_GetSize() & @CRLF & 'format quick fs=ntfs label="WinPE Data"' & @CRLF & 'assign letter=' & $s_DataDrive & @CRLF & 'Exit')
    Diskpart_CreateScriptFile('initboot.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=fat32 label="BOOTFILES"' & @CRLF & 'assign letter=' & $s_BootDrive & @CRLF & 'Active' & @CRLF & 'Exit')
EndFunc   ;==>Format_Prepare

Func Format_Run() ; format the selected drive
    Local $as_DiskPart[8][2] = [ _
            [7, 0], _
            ["Cleaning Drive", 'clean.dat'], _
            ["Cleaning Drive", 'scrub.dat'], _
            ["Cleaning Drive", 'clean.dat'], _
            ["Resetting Disk Attributes", 'attrib.dat'], _
            ["Converting Layout to MBR", 'convert.dat'], _
            ["Creating Data Partition", 'initdata.dat'], _
            ["Creating Boot Partition", 'initboot.dat'] _
            ]

    Local $s_Program = @ComSpec & ' /c diskpart /s ' & '"' & CacheFolder_GetPath()

    For $i = 1 To $as_DiskPart[0][0]
        ProgressSet($i * 13 & "%", $as_DiskPart[$i][0])
        RunWait($s_Program & $as_DiskPart[$i][1] & '"', @WorkingDir, @SW_HIDE)
        Sleep(750)
    Next
EndFunc   ;==>Format_Run

; #FUNCTION# ====================================================================================================================
; Name ..........: GUI_CentreGUI
; Description ...: Centre a child gui to it's parent using the parent's co-ordinates
; Syntax ........: GUI_CentreGUI($h_OldGui, $h_Child)
; Parameters ....: $h_OldGui - a handle value. Handle of the parent gui
;                  $h_Child  - a handle value. Handle of the child gui
; Return values .: None
; Author ........: Benners
; Modified ......:
; ===============================================================================================================================
Func GUI_CentreGUI($h_OldGui, $h_Child) ; centre a child gui to it's parent
    Local _
            $ai_ParentPos = WinGetPos($h_OldGui, ''), _ ; _     get the position of the parent gui
            $ai_ChildSize = WinGetClientSize($h_Child, '') ; _  get the size of the viewer gui
    Local _
            $i_Xcord = $ai_ParentPos[0] + ($ai_ParentPos[2] / 2) - ($ai_ChildSize[0] / 2), _
            $i_Ycord = $ai_ParentPos[1] + ($ai_ParentPos[3] / 2) - ($ai_ChildSize[1] / 2)

    WinMove($h_Child, '', $i_Xcord, $i_Ycord) ; move the child gui to the centre of the parent gui
EndFunc   ;==>GUI_CentreGUI

Func GUI_CloseGUI() ; close the gui
    ISO_Unmount()
    CacheFolder_DeleteFiles()
    Exit
EndFunc   ;==>GUI_CloseGUI

Func GUI_CreateGUI() ; draw the gui
    $h_MainGUI = GUICreate('BurnTool (XPE/SE) v2.0', 300, 287)

    GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CloseGUI")

    GUISetIcon(@WorkingDir & '\USBTool.ico', 1)
    GUISetBkColor(0x797979)
    GUICtrlCreateLabel('Select a disk to use...', 20, 10, 280)

    $id_DiskList = GUICtrlCreateTreeView(10, 30, 280, 150)
    DiskList_Load()

    GUICtrlCreateButton('Refresh List', 110, 187, 80, 25)
    GUICtrlSetOnEvent(-1, "DiskList_Load")
    GUICtrlSetState(-1, $GUI_FOCUS)

    GUICtrlCreateLabel('________________________________________', 30, 210, 280, 30)

    $id_BurnBtn = GUICtrlCreateButton('Burn', 90, 232, 120, 40)
    GUICtrlSetOnEvent(-1, "BurnPressed")
    GUICtrlSetState(-1, $GUI_DISABLE)

    GUISetState()

    ; Just idle around
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>GUI_CreateGUI

; #FUNCTION# ====================================================================================================================
; Name ..........: GUI_SwitchGUI
; Description ...: Switches the current active window to be associated with running GUI functions.
; Syntax ........: GUI_SwitchGUI($h_NewGui, $h_OldGui[, $i_EventMode = Default[, $i_DisableOldGui = Default[, $i_HideOldGui = Default[,
;                  $i_DeleteOldGui = Default]]]])
; Parameters ....: $h_NewGui        - The handle of the gui that is to be the current window
;                  $h_OldGui        - The handle of the gui that is to relinquish control
;                  $i_EventMode     - [optional] an integer value. Sets the Opt("GUIOnEventMode") for notifications (enable\disable)
;                                     Default is disabled ($GA_ONEVENTMODENO)
;                  $i_DisableOldGui - [optional] an integer value. Changes the state of the $h_OldGui window (enable\disable)
;                                     Default is enabled ($GA_DISABLEOLDGUINO)
;                  $i_HideOldGui    - [optional] an integer value. Hide the old gui
;                  $i_DeleteOldGui  - [optional] an integer value. Deletes the $h_OldGui window and all controls that it contains (yes\no)
;                                     Default is no ($GA_DELETEOLDGUINO)
; Return values .: None
; Author ........: Benners
; Modified ......:
; Remarks .......:
; ===============================================================================================================================
Func GUI_SwitchGUI($h_NewGui, $h_OldGui, $i_EventMode = Default, $i_DisableOldGui = Default, $i_HideOldGui = Default, $i_DeleteOldGui = Default)
    If $i_EventMode = Default Then $i_EventMode = $GA_ONEVENTMODENO
    If $i_DisableOldGui = Default Then $i_DisableOldGui = $GA_DISABLEOLDGUINO
    If $i_HideOldGui = Default Then $i_HideOldGui = $GA_HIDEOLDGUINO
    If $i_DeleteOldGui = Default Then $i_DeleteOldGui = $GA_DELETEOLDGUINO

    Opt("GUIOnEventMode", $i_EventMode) ;_                          set on event mode (disabled or enabled)
    GUISwitch($h_NewGui) ;_                                         switch control to the new GUI.
    GUISetState(@SW_ENABLE, $h_NewGui) ;_                           enable the new gui
    GUISetState(@SW_RESTORE, $h_NewGui) ;_                          undo a window minimization
    GUISetState(@SW_SHOW, $h_NewGui) ;_                             show the gui
    If $i_DisableOldGui Then GUISetState(@SW_DISABLE, $h_OldGui) ;_ disable the old GUI.
    If $i_HideOldGui Then GUISetState(@SW_HIDE, $h_OldGui) ; _      hide the old gui
    If $i_DeleteOldGui Then GUIDelete($i_DeleteOldGui) ;_           destroy the old gui
EndFunc   ;==>GUI_SwitchGUI

Func Initialise() ; run pre checks before program starts
    ISO_CheckWasDropped() ; _                   check for a cmdline argument (iso file was dropped on the exe)
    ISO_Mount() ; _                             mount the dropped iso
    $s_MountedDrive = ISO_GetDriveLetter() ; _  get the drive letter for the mounted iso, returns without trailing '\'
    BootWim_Check() ; _                         check for the bootwim file on the mounted drive
    CacheFolder_DeleteFiles() ; _               delete the cache folder
    DirCreate(CacheFolder_GetPath()) ; _        create the cache folder
EndFunc   ;==>Initialise

Func ISO_CheckWasDropped() ; check that an iso was dropped on to the exe
    If $CmdLine[0] = 0 Then ; no file was dropped or passed via the command line
        MsgBox( _
                $MB_ICONERROR, _
                "Attention: ", _
                "This program cannot be run directly!" & @CRLF & "Please drag an ISO onto the program to begin...")

        GUI_CloseGUI()
    EndIf
EndFunc   ;==>ISO_CheckWasDropped

Func ISO_GetDriveLetter() ; get the drive letter of the mounted iso, returns with trailing '\'
    Local $s_MarkerFile = 'BOOTMGR'
    Local $s_IsoDrive = ''

    Local $as_CDROM = DriveGetDrive($DT_CDROM)

    For $i = 1 To $as_CDROM[0]
        If FileExists($as_CDROM[$i] & '\' & $s_MarkerFile) Then
            If Not _WinAPI_IsWritable($as_CDROM[$i]) Then $s_IsoDrive = $as_CDROM[$i]
        EndIf
    Next

    If $s_IsoDrive = "" Then
        MsgBox( _
                $MB_ICONERROR, _
                "Attention: ", _
                $s_MarkerFile & " NOT DETECTED!!!" & @CRLF & "This tool is designed for XPE" & @CRLF & "and SE projects only.")

        GUI_CloseGUI()
    EndIf

    Return StringUpper($s_IsoDrive)
EndFunc   ;==>ISO_GetDriveLetter

Func ISO_Mount() ; mount the droppped iso
    RunWait('cmd /c powershell.exe ' & '"Mount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE)
EndFunc   ;==>ISO_Mount

Func ISO_Unmount() ; unmount the dropped iso
    ; check for mounted drive and unmount if required
    If $s_MountedDrive <> '' Then RunWait('cmd /c powershell.exe ' & '"Dismount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE)
EndFunc   ;==>ISO_Unmount

 

bobomb-test.7z

Edited by bobomb
Link to comment
Share on other sites

  • bobomb changed the title to Copy issues with x64 binary on Win10/11 hosts, x86 is working fine.

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...