Jump to content

MadDogVachon
 Share

Recommended Posts

Hi everyone,

Here is my script that does the job of the original BootSectGui. I wrote it because I needed a BootSectGui that works in WinPE x64 environment. The original works only in x86 envoronment. It is free to use, modify and distribute. I coded first in French and then in English, it may have some mistranslation.

In the 7z attached file you have these files:

  • BootSectGui - original - Main.png    ->  The original Main window of BootSectGui
  • BootSectGui - original - Log.png     ->  The original Log window of BootSectGui
  • BootSectGui - original.exe               ->  The original BooSectGui.exe program
  • BootSectGui_x86_x64.au3              ->  My code
  • BootSectGui_x86.exe                      ->  My program x86 version 1.3
  • BootSectGui_x64.exe                      ->  My program x64 version 1.3
  • BootSectGui_x86_x64 1.2.1.au3     ->  My code for 1.2.1
  • BootSectGui_x86 1.2.1.exe             ->  My program 1.2.1 x86 version

  • BootSectGui_x64 1.2.1.exe             ->  My program 1.2.1 x64 version
  • BootSectGui_x64 - Main.png          ->  My Main window

  • BootSectGui_x64 - Log.png            ->  My Log window
  • BootSectGui_x64 - Main 1.2.1.png  ->  My Main window 1.2.1

  • BootSectGui.psd                             ->  My "code" for the ico files in Photoshop format
  • BootSectGui BSG 64.ico                 ->  The icon used with my program, in 64 dots
  • BootSectGui BSG 256.ico               ->  The same in 256 dots
  • BootSectGui G BS 64.ico                ->  Another icon that looks more like the original one, in 64 dots
  • BootSectGui G BS 256.ico              ->  The same in 256 dots

Enjoy!

MDV

Here's the code:

#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=BootSectGui BSG 64.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=New BootSectGui
#AutoIt3Wrapper_Res_Description=New BootSectGui that works in WinPE x86 and x64
#AutoIt3Wrapper_Res_Fileversion=1.3
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.8.1
    Author:         MadDogVachon

    Script Function: A Gui for BootSect that work in WinPE x64 environment (also in WinPE x86 and Windows x86 x64)

    Thanks to AZJIO for the improvement of my code!

#ce ----------------------------------------------------------------------------

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <GuiConstantsEx.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)

Local $Title = "BootSectGui - AutoIt3", $sPathBootSect, $sDriveSelectionItems, $sDriveSelectionFirst, $sBootCode, $sp
; GUI + ID
Local $hBootSectGuiMain, $msg, $iSingleDrive, $iAllDrives, $iSYSDrive, $iNT60, $iNT52, $iMBRYesNo, $iForceYesNo, $iDriveSelection, $iBtnWrite, $iQuit

If FileExists(@WorkingDir & "\bootsect.exe") Then
    $sPathBootSect = @WorkingDir & "\bootsect.exe"
ElseIf FileExists(@ScriptDir & "\bootsect.exe") Then
    $sPathBootSect = @ScriptDir & "\bootsect.exe"
ElseIf FileExists(@SystemDir & "\bootsect.exe") Then
    $sPathBootSect = @SystemDir & "\bootsect.exe"
ElseIf FileExists(@WindowsDir & "\bootsect.exe") Then
    $sPathBootSect = @WindowsDir & "\bootsect.exe"
Else
    MsgBox(16 + 262144, $Title, "The necessary 'BootSect.exe' file not found!" & @CRLF & @CRLF & "The program will end now!")
    Exit
EndIf

;Main Menu
$hBootSectGuiMain = GUICreate($Title, 525, 175)

Local $GuiX = 18, $GuiY = 20
; Group Drive(s)
GUICtrlCreateGroup("Write master boot code into", $GuiX, $GuiY, 189, 130)
$iAllDrives = GUICtrlCreateRadio("All Drives", $GuiX + 15, $GuiY + 20, 80)
$iSingleDrive = GUICtrlCreateRadio("Single Drive:", $GuiX + 15, $GuiY + 45, 80)
GUICtrlSetState(-1, $GUI_CHECKED)

; =================================
$sp = Chr(1)
Opt("GUIDataSeparatorChar", $sp)
$sDriveSelectionItems = _GetDrv()
If Not $sDriveSelectionItems Then ; An error occurred when retrieving the drives.
    MsgBox(4096, $Title, "Error on querying drives" & @CRLF & @CRLF & "The program will end now!")
    Exit
EndIf
$sDriveSelectionFirst = StringRegExp($sDriveSelectionItems, '(?:\A|\001)([C-Z]: Fixed.*?)(?=\001)', 1)
If @error Then
    $sDriveSelectionFirst = StringLeft($sDriveSelectionItems, StringInStr($sDriveSelectionItems & $sp, $sp) - 1)
Else
    $sDriveSelectionFirst = $sDriveSelectionFirst[0]
EndIf
$iDriveSelection = GUICtrlCreateCombo("", $GuiX + 15, $GuiY + 70, 160, 25, $WS_VSCROLL + $CBS_DROPDOWNLIST)
GUICtrlSetFont(-1, -1, -1, 0, "Courier New")
GUICtrlSendMsg(-1, 0x160, 370, 0)
GUICtrlSetData(-1, $sDriveSelectionItems, $sDriveSelectionFirst)
; =================================

$iSYSDrive = GUICtrlCreateRadio("System Drive", $GuiX + 15, $GuiY + 95, 80)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

$GuiX += 205
; Group Windows version
GUICtrlCreateGroup("Select master boot code version", $GuiX, $GuiY, 185, 80)
$iNT60 = GUICtrlCreateRadio("Windows Vista/7/8 ""/NT60""", $GuiX + 15, $GuiY + 20, 160)
GUICtrlSetState(-1, $GUI_CHECKED)
$iNT52 = GUICtrlCreateRadio("Windows XP ""/NT52""", $GuiX + 15, $GuiY + 45, 130)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

$GuiX += 200
; Group Master Boot Record
GUICtrlCreateGroup("Options", $GuiX, $GuiY, 85, 80)
$iMBRYesNo = GUICtrlCreateCheckbox("MBR", $GuiX + 15, $GuiY + 20, 60)
GUICtrlSetState(-1, $GUI_CHECKED)
$iForceYesNo = GUICtrlCreateCheckbox("Force", $GuiX + 15, $GuiY + 45, 60)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

; Group Button
Local $ButtonX = 18 + 205 + 17, $ButtonY = $GuiY + 95
$iBtnWrite = GUICtrlCreateButton("Write master boot code", $ButtonX, $ButtonY, 150, 40)
$iQuit = GUICtrlCreateButton("Quit", $ButtonX + 183, $ButtonY, 85, 40)
GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button

GUISetState()

; Run the GUI until the dialog is closed
While 1
    Switch GUIGetMsg()
        Case $iBtnWrite
            If GUICtrlRead($iNT60) = $GUI_CHECKED Then
                $sBootCode = "/NT60"
            ElseIf GUICtrlRead($iNT52) = $GUI_CHECKED Then
                $sBootCode = "/NT52"
            EndIf
            If GUICtrlRead($iSingleDrive) = $GUI_CHECKED Then
                BootSectLog(StringLeft(GUICtrlRead($iDriveSelection), 2))
            ElseIf GUICtrlRead($iAllDrives) = $GUI_CHECKED Then
                BootSectLog("All")
            Else
                BootSectLog("SYS")
            EndIf
        Case $iSingleDrive
            GUICtrlSetState($iDriveSelection, $GUI_ENABLE)
        Case $iAllDrives, $iSYSDrive
            GUICtrlSetState($iDriveSelection, $GUI_DISABLE)
        Case $GUI_EVENT_CLOSE, $iQuit
            Exit
    EndSwitch
WEnd

Func BootSectLog($sBootSectDrive)
    Local $hBootSectGuiLog, $iPID, $sBootSectInProgress, $iBootSectLog, $sLine, $iWidth = 530, $iHeight = 330, $iClose, $sMBR, $sForce
    If GUICtrlRead($iMBRYesNo) = $GUI_CHECKED Then $sMBR = " /mbr"
    If GUICtrlRead($iForceYesNo) = $GUI_CHECKED Then $sForce = " /force"
    $iPID = Run(@ComSpec & ' /c "' & $sPathBootSect & '" ' & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

    $sBootSectInProgress = "Executing:" & @CRLF & "                  Bootsect " & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce & @CRLF & @CRLF & "--------------------------------------------------------------------------------"

    GUISetState(@SW_DISABLE, $hBootSectGuiMain)
    $hBootSectGuiLog = GUICreate("BootSect Log", $iWidth, $iHeight, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_POPUP, -1, $hBootSectGuiMain)
    $iBootSectLog = GUICtrlCreateEdit($sBootSectInProgress, 2, 2, $iWidth, $iHeight - 60)
    $iClose = GUICtrlCreateButton("Close", $iWidth / 2 - 148, $iHeight - 38, 295, 30)
    GUICtrlSetState(-1, $GUI_DISABLE) ; Disable "Close" button
    GUISetState(@SW_SHOW, $hBootSectGuiLog)

    _GUICtrlEdit_AppendText($iBootSectLog, @CRLF) ; Add space

    While 1
        $sLine = StdoutRead($iPID)
        If @error Then ExitLoop
        If $sLine Then _GUICtrlEdit_AppendText($iBootSectLog, @CRLF & $sLine)
    WEnd
    _GUICtrlEdit_AppendText($iBootSectLog, @CRLF & "--------------------------------------------------------------------------------" & @CRLF & @CRLF & "Bootsect has terminated itself")
    GUICtrlSetState($iClose, $GUI_ENABLE) ; Enable "Close" button
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $iClose Then
            GUISetState(@SW_ENABLE, $hBootSectGuiMain)
            GUIDelete($hBootSectGuiLog)
            ExitLoop
        EndIf
    WEnd
EndFunc   ;==>BootSectLog

Func _GetDrv()
    Local $sInfo = _ComboListDrive('Fixed')
    $sInfo &= _ComboListDrive('Removable')
    Return StringTrimLeft($sInfo, 1)
EndFunc   ;==>_GetDrv

Func _ComboListDrive($Type) ; coded by AZJIO (2013.01.26)
    Local $aDrive = DriveGetDrive($Type), $list = '', $sString, $sLabel
    If @error Then Return ''
    If $Type = 'Removable' Then $Type = 'Rem'
    For $i = 1 To $aDrive[0]
        If $aDrive[$i] = 'A:' Then ContinueLoop
        $sLabel = DriveGetLabel($aDrive[$i])
        If StringLen($sLabel) > 15 Then $sLabel = StringLeft($sLabel, 12) & '...'
        $sString = StringFormat("%-2s %-5s %-15s %-5s ", StringUpper($aDrive[$i]), $Type, $sLabel, _
                DriveGetFileSystem($aDrive[$i])) & _GetSize(DriveSpaceTotal($aDrive[$i])) & ' Gb'
        $list &= $sp & $sString
    Next
    Return $list
EndFunc   ;==>_ComboListDrive

Func _GetSize($s) ; coded by AZJIO
    $s = StringFormat('%.03f', $s / 1024)
    If StringLen($s) > 7 Then $s = StringRegExpReplace(StringTrimRight($s, 4), '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ') & StringRight($s, 4)
    Return StringFormat('%9s', $s) ; 9 ????????
EndFunc   ;==>_GetSize

- - - - -

Edit 1: Corrected mistype in topic title, updated code with JFX recommendation and updated BootSectGui_x64 - Main.png with the new code. Version 1.1

Edit 2: Added /mbr (by default). Corrected the line to execute bootsect.exe using the variable $BootSect. Version 1.1.1

Edit 3: Added /force. Corrected a bug when not founding boosect.exe. Added SYS (system drive) in the list. Updated BootSectGui_x64 - Main.png, BootSectGui_x64 - Log.png and exe files. Version 1.2

Edit 4: Added improvement by AZJIO and updated files. Version 1.3

Edit 5: Little update of code ;) added version 1.2.1 with improvement of AZJIO and a simple list of drives.

BootSectGui_x64.7z

Edited by MadDogVachon

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

Hi JFX,

I updated my code. I noticed that the log of the original BootSectGui does not include the /mbr switch. But it does the job every time I used it. What's the difference? I don't really understand what Microsoft says (in French here):

Updates the master boot record without changing the partition table on sector 0 of the disk that contains the partition specified by SYSALL, or <drive letter>

 

Thanks!

MDV

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

The /mbr switch was added with ADK 2.1

Microsoft calls everything master boot code, but everyone else differentiate between the code in MBR and PBR.

The MBR tells the BIOS, which partiton to start.
The PBR tells which boot loader to execute NTLDR or BOOTMGR

New hard disks usually have no master boot code and many partition software also doesn't write one.
So to be absolutely sure that the disk setup will be bootable one can use the /mbr switch.

Link to comment
Share on other sites

@ JFX

Thanks! I will make /mbr switch by default.

@AZJIO

Thanks, very brillant code! As a beginner, I will not go in that direction because I don't understand all you wrote to make a list of hard drives like that. I updated my gui to add /mbr and /force options like your. I noticed that your BootSectGui.exe will work only in WinPE x86 environment.

Now my gui looks like that:

https://db.tt/etbHaRzR

https://db.tt/Hs4sTeTf

MDV

- - - -

Edit: Updated images after the improvement of AZJIO.

Edited by MadDogVachon

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

Link to comment
Share on other sites

@MadDogVachon

I did upgrade. Corrected only obvious errors. Renamed some variables.

#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=BootSectGui BSG 64.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=New BootSectGui
#AutoIt3Wrapper_Res_Description=New BootSectGui that works in WinPE x86 and x64
#AutoIt3Wrapper_Res_Fileversion=1.3
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.8.1
    Author:         MadDogVachon
    
    Script Function:
    A Gui for BootSect that work in WinPE x64 environment (also in WinPE x86 and Windows x86 x64)
    
#ce ----------------------------------------------------------------------------

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <GuiConstantsEx.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)

Local $Title = "BootSectGui - AutoIt3", $sPathBootSect, $sDriveSelectionItems, $sDriveSelectionFirst, $sBootCode, $sp
; GUI + ID
Local $hBootSectGuiMain, $msg, $iSingleDrive, $iAllDrives, $iSYSDrive, $iNT60, $iNT52, $iMBRYesNo, $iForceYesNo, $iDriveSelection, $iBtnWrite, $iQuit

If FileExists(@WorkingDir & "\bootsect.exe") Then
    $sPathBootSect = @WorkingDir & "\bootsect.exe"
ElseIf FileExists(@ScriptDir & "\bootsect.exe") Then
    $sPathBootSect = @ScriptDir & "\bootsect.exe"
ElseIf FileExists(@SystemDir & "\bootsect.exe") Then
    $sPathBootSect = @SystemDir & "\bootsect.exe"
ElseIf FileExists(@WindowsDir & "\bootsect.exe") Then
    $sPathBootSect = @WindowsDir & "\bootsect.exe"
Else
    MsgBox(16 + 262144, $Title, "The necessary 'BootSect.exe' file not found!" & @CRLF & @CRLF & "The program will end now!")
    Exit
EndIf

;Main Menu
$hBootSectGuiMain = GUICreate($Title, 525, 175)

Local $GuiX = 18, $GuiY = 20
; Group Drive(s)
GUICtrlCreateGroup("Write master boot code into", $GuiX, $GuiY, 189, 130)
$iAllDrives = GUICtrlCreateRadio("All Drives", $GuiX + 15, $GuiY + 20, 80)
$iSingleDrive = GUICtrlCreateRadio("Single Drive:", $GuiX + 15, $GuiY + 45, 80)
GUICtrlSetState(-1, $GUI_CHECKED)

; =================================
$sp = Chr(1)
Opt("GUIDataSeparatorChar", $sp)
$sDriveSelectionItems = _GetDrv()
If Not $sDriveSelectionItems Then ; An error occurred when retrieving the drives.
    MsgBox(4096, $Title, "Error on querying drives" & @CRLF & @CRLF & "The program will end now!")
    Exit
EndIf
$sDriveSelectionFirst = StringRegExp($sDriveSelectionItems, '(?:\A|\001)([C-Z]: Fixed.*?)(?=\001)', 1)
If @error Then
    $sDriveSelectionFirst = StringLeft($sDriveSelectionItems, StringInStr($sDriveSelectionItems & $sp, $sp) - 1)
Else
    $sDriveSelectionFirst = $sDriveSelectionFirst[0]
EndIf
$iDriveSelection = GUICtrlCreateCombo("", $GuiX + 15, $GuiY + 70, 160, 25, $WS_VSCROLL + $CBS_DROPDOWNLIST)
GUICtrlSetFont(-1, -1, -1, 0, "Courier New")
GUICtrlSendMsg(-1, 0x160, 370, 0)
GUICtrlSetData(-1, $sDriveSelectionItems, $sDriveSelectionFirst)
; =================================

$iSYSDrive = GUICtrlCreateRadio("System Drive", $GuiX + 15, $GuiY + 95, 80)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

$GuiX += 205
; Group Windows version
GUICtrlCreateGroup("Select master boot code version", $GuiX, $GuiY, 185, 80)
$iNT60 = GUICtrlCreateRadio("Windows Vista/7/8 ""/NT60""", $GuiX + 15, $GuiY + 20, 160)
GUICtrlSetState(-1, $GUI_CHECKED)
$iNT52 = GUICtrlCreateRadio("Windows XP ""/NT52""", $GuiX + 15, $GuiY + 45, 130)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

$GuiX += 200
; Group Master Boot Record
GUICtrlCreateGroup("Options", $GuiX, $GuiY, 85, 80)
$iMBRYesNo = GUICtrlCreateCheckbox("MBR", $GuiX + 15, $GuiY + 20, 60)
GUICtrlSetState(-1, $GUI_CHECKED)
$iForceYesNo = GUICtrlCreateCheckbox("Force", $GuiX + 15, $GuiY + 45, 60)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group

; Group Button
Local $ButtonX = 18 + 205 + 17, $ButtonY = $GuiY + 95
$iBtnWrite = GUICtrlCreateButton("Write master boot code", $ButtonX, $ButtonY, 150, 40)
$iQuit = GUICtrlCreateButton("Quit", $ButtonX + 183, $ButtonY, 85, 40)
GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button

GUISetState()

; Run the GUI until the dialog is closed
While 1
    Switch GUIGetMsg()
        Case $iBtnWrite
            If GUICtrlRead($iNT60) = $GUI_CHECKED Then
                $sBootCode = "/NT60"
            ElseIf GUICtrlRead($iNT52) = $GUI_CHECKED Then
                $sBootCode = "/NT52"
            EndIf
            If GUICtrlRead($iSingleDrive) = $GUI_CHECKED Then
                BootSectLog(StringLeft(GUICtrlRead($iDriveSelection), 2))
            ElseIf GUICtrlRead($iAllDrives) = $GUI_CHECKED Then
                BootSectLog("All")
            Else
                BootSectLog("SYS")
            EndIf
        Case $iSingleDrive
            GUICtrlSetState($iDriveSelection, $GUI_ENABLE)
        Case $iAllDrives, $iSYSDrive
            GUICtrlSetState($iDriveSelection, $GUI_DISABLE)
        Case $GUI_EVENT_CLOSE, $iQuit
            Exit
    EndSwitch
WEnd

Func BootSectLog($sBootSectDrive)
    Local $hBootSectGuiLog, $iPID, $sBootSectInProgress, $iBootSectLog, $sLine, $iWidth = 530, $iHeight = 330, $iClose, $sMBR, $sForce
    If GUICtrlRead($iMBRYesNo) = $GUI_CHECKED Then $sMBR = " /mbr"
    If GUICtrlRead($iForceYesNo) = $GUI_CHECKED Then $sForce = " /force"
    $iPID = Run(@ComSpec & ' /c "' & $sPathBootSect & '" ' & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

    $sBootSectInProgress = "Executing:" & @CRLF & "                  Bootsect " & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce & @CRLF & @CRLF & "--------------------------------------------------------------------------------"

    GUISetState(@SW_DISABLE, $hBootSectGuiMain)
    $hBootSectGuiLog = GUICreate("BootSect Log", $iWidth, $iHeight, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_POPUP, -1, $hBootSectGuiMain)
    $iBootSectLog = GUICtrlCreateEdit($sBootSectInProgress, 2, 2, $iWidth, $iHeight - 60)
    $iClose = GUICtrlCreateButton("Close", $iWidth / 2 - 148, $iHeight - 38, 295, 30)
    GUICtrlSetState(-1, $GUI_DISABLE) ; Disable "Close" button
    GUISetState(@SW_SHOW, $hBootSectGuiLog)

    _GUICtrlEdit_AppendText($iBootSectLog, @CRLF) ; Add space

    While 1
        $sLine = StdoutRead($iPID)
        If @error Then ExitLoop
        If $sLine Then _GUICtrlEdit_AppendText($iBootSectLog, @CRLF & $sLine)
    WEnd
    _GUICtrlEdit_AppendText($iBootSectLog, @CRLF & "--------------------------------------------------------------------------------" & @CRLF & @CRLF & "Bootsect has terminated itself")
    GUICtrlSetState($iClose, $GUI_ENABLE) ; Enable "Close" button
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $iClose Then
            GUISetState(@SW_ENABLE, $hBootSectGuiMain)
            GUIDelete($hBootSectGuiLog)
            ExitLoop
        EndIf
    WEnd
EndFunc   ;==>BootSectLog

Func _GetDrv()
    Local $sInfo = _ComboListDrive('Fixed')
    $sInfo &= _ComboListDrive('Removable')
    Return StringTrimLeft($sInfo, 1)
EndFunc   ;==>_GetDrv

Func _ComboListDrive($Type) ; coded by AZJIO (2013.01.26)
    Local $aDrive = DriveGetDrive($Type), $list = '', $sString, $sLabel
    If @error Then Return ''
    If $Type = 'Removable' Then $Type = 'Rem'
    For $i = 1 To $aDrive[0]
        If $aDrive[$i] = 'A:' Then ContinueLoop
        $sLabel = DriveGetLabel($aDrive[$i])
        If StringLen($sLabel) > 15 Then $sLabel = StringLeft($sLabel, 12) & '...'
        $sString = StringFormat("%-2s %-5s %-15s %-5s ", StringUpper($aDrive[$i]), $Type, $sLabel, _
                DriveGetFileSystem($aDrive[$i])) & _GetSize(DriveSpaceTotal($aDrive[$i])) & ' Gb'
        $list &= $sp & $sString
    Next
    Return $list
EndFunc   ;==>_ComboListDrive

Func _GetSize($s) ; coded by AZJIO
    $s = StringFormat('%.03f', $s / 1024)
    If StringLen($s) > 7 Then $s = StringRegExpReplace(StringTrimRight($s, 4), '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ') & StringRight($s, 4)
    Return StringFormat('%9s', $s) ; 9 терабайт
EndFunc   ;==>_GetSize

.

.

.

______________________________________________

BootSectGui - My version (EXE + source code + icon)

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_OutFile=BootSectGui.exe
; #AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_OutFile_X64=BootSectGuiX64.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_icon=BootSectGui.ico
#AutoIt3Wrapper_UseUpx=n
; #AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=-
#AutoIt3Wrapper_Res_Description=BootSectGui.exe
#AutoIt3Wrapper_Res_Fileversion=0.2.0.0
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=n
#AutoIt3Wrapper_Res_LegalCopyright=AZJIO
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_AU3Check=n
://////=__=.
://////=__=..
://////=__=
://////=__=_
://////=__=
://////=__=
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
; #Obfuscator_Parameters=/SO
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

;  @AZJIO 2013.09.20 AutoIt3_v3.3.8.1

Opt('MustDeclareVars', 1)
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <UserGUI.au3>

Local $sTitle = "BootSectGui", $sPathBootSect, $sList, $Current, $sp, $sLog, $tmp, $sDash
; GUI + ID
Local $hGUI, $msg, $iNT60, $iNT52, $iCh_MBR, $iCh_Force, $iCombo, $iBtnStart, $iBtnHelp, $iBtnLog, $iStatusBar

Local $Lng[22]
$Lng[1] = 'BootSect.exe not found.'
$Lng[2] = 'Completion of the program.'
$Lng[3] = 'Not found any disk'
$Lng[4] = 'Completion of the program'
$Lng[5] = 'Operating system'
$Lng[6] = '/nt52 (ntldr, Windows XP)'
$Lng[7] = '/nt60 (bootmgr, Windows Vista/7/8)'
$Lng[8] = 'Options'
$Lng[9] = 'MBR'
$Lng[10] = 'Force'
$Lng[11] = 'Log'
$Lng[12] = 'Start'
$Lng[13] = 'Error'
$Lng[14] = 'The log is available after the operation.'
$Lng[15] = '(successfully)'
$Lng[16] = 'Options'
$Lng[17] = 'Bootsect = Start'
$Lng[18] = 'Bootsect = End'
$Lng[19] = 'Viewing'
$Lng[20] = 'Gb'
$Lng[21] = 'Error'

If @OSLang = 0419 Then
    $Lng[1] = 'Не найден BootSect.exe.'
    $Lng[2] = 'Завершение программы.'
    $Lng[3] = 'Не найдено ни одного диска'
    $Lng[4] = 'Завершение программы'
    $Lng[5] = 'Операционная система'
    ; $Lng[6] = '/nt52 (ntldr, Windows XP)'
    ; $Lng[7] = '/nt60 (bootmgr, Windows Vista/7/8)'
    $Lng[8] = 'Опции'
    ; $Lng[9] = 'MBR'
    ; $Lng[10] = 'Force'
    $Lng[11] = 'Лог'
    $Lng[12] = 'Старт'
    $Lng[13] = 'Ошибка'
    $Lng[14] = 'Лог доступен после выполнения операции.'
    $Lng[15] = '(успешно)'
    $Lng[16] = 'Опции'
    $Lng[17] = 'Bootsect = Начало'
    $Lng[18] = 'Bootsect = Конец'
    $Lng[19] = 'Просмотр'
    $Lng[20] = 'Гб'
    $Lng[21] = 'Ошибка'
EndIf
If StringLen($Lng[20]) > 2 Then $Lng[20] = StringLeft($Lng[20], 2)

_AddDash('-', 84, $Lng[16])
_AddDash('-', 84, $Lng[17])
_AddDash('-', 84, $Lng[18])

FileChangeDir(@ScriptDir)

$sPathBootSect = _GetPath('bootsect.exe')
If @error Then Exit MsgBox(16 + 262144, $sTitle, $Lng[1] & @LF & $Lng[2])

$sp = Chr(1)
Opt('GUIDataSeparatorChar', $sp)
$sList = _GetDrv()
If Not $sList Then Exit MsgBox(4096, $sTitle, $Lng[3] & @LF & $Lng[4])

$hGUI = GUICreate($sTitle, 440, 130)
If Not @Compiled Then GUISetIcon(@ScriptDir & '\BootSectGui.ico')

$Current = StringRegExp($sList, '(?:\A|\001)([C-Z]: Fixed.*?)(?=\001)', 1)
If @error Then
    $Current = StringLeft($sList, StringInStr($sList & $sp, $sp) - 1)
Else
    $Current = $Current[0]
EndIf
$iCombo = GUICtrlCreateCombo('', 20, 16, 400, 25, $WS_VSCROLL + $CBS_DROPDOWNLIST)
GUICtrlSetFont(-1, -1, -1, 0, 'Courier New')
GUICtrlSendMsg(-1, 0x160, 370, 0)
GUICtrlSetData(-1, $sList & $sp & '/SYS' & $sp & '/ALL', $Current)

; Операционная система
GUICtrlCreateGroup($Lng[5], 20, 45, 200, 60)
$iNT52 = GUICtrlCreateRadio($Lng[6], 27, 60, 188, 20)
$iNT60 = GUICtrlCreateRadio($Lng[7], 27, 80, 188, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup('', -99, -99, 1, 1) ;close group

; Опции
GUICtrlCreateGroup($Lng[8], 230, 45, 62, 60)
$iCh_MBR = GUICtrlCreateCheckbox($Lng[9], 237, 60, 53, 20)
; GUICtrlSetState(-1, $GUI_CHECKED)
$iCh_Force = GUICtrlCreateCheckbox($Lng[10], 237, 80, 53, 20)
GUICtrlCreateGroup('', -99, -99, 1, 1) ;close group

; $iBtnHelp = GUICtrlCreateButton('Help', 300, 50, 57, 27)
; GUICtrlSetState(-1, $GUI_FOCUS + $GUI_DEFBUTTON)
; $iBtnLog = GUICtrlCreateButton($Lng[11], 363, 50, 57, 27)
; $iBtnStart = GUICtrlCreateButton($Lng[12], 300, 80, 120, 27)

$iBtnHelp = GUICtrlCreateButton('?', 300, 50, 30, 27)
GUICtrlSetState(-1, $GUI_FOCUS + $GUI_DEFBUTTON)
$iBtnLog = GUICtrlCreateButton($Lng[11], 300, 80, 30, 27)
$iBtnStart = GUICtrlCreateButton($Lng[12], 333, 50, 87, 57)
GUICtrlSetFont(-1, 12)

$iStatusBar = GUICtrlCreateLabel('bootsect.exe' & _GetComString(), 20, 110, 420, 17)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $iBtnLog
            If $sLog Then
                _Viewing($hGUI, $sLog)
            Else
                MsgBox(0, $Lng[13], $Lng[14], 0, $hGUI)
            EndIf
        Case $iBtnHelp
            $tmp = _Help()
            If $tmp Then _Viewing($hGUI, $tmp)
        Case $iBtnStart
            $sLog = _BootSect()
        Case $iCombo, $iNT52, $iNT60, $iCh_MBR, $iCh_Force
            GUICtrlSetData($iStatusBar, 'bootsect.exe' & _GetComString())
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GetComString()
    Local $sComString, $tmp
    If GUICtrlRead($iNT60) = $GUI_CHECKED Then
        $sComString &= ' /nt60'
    Else
        $sComString &= ' /nt52'
    EndIf
    $tmp = GUICtrlRead($iCombo)
    Switch $tmp
        Case '/SYS'
            $sComString &= ' /SYS'
        Case '/ALL'
            $sComString &= ' /ALL'
        Case Else
            $tmp = StringRegExp($tmp, '(?i)^.{6}([a-z]:).+', 1)
            If @error Then
                Return SetError(1, 0, $Lng[21])
            Else
                $sComString &= ' ' & $tmp[0]
            EndIf
    EndSwitch
    If GUICtrlRead($iCh_MBR) = $GUI_CHECKED Then $sComString &= ' /mbr'
    If GUICtrlRead($iCh_Force) = $GUI_CHECKED Then $sComString &= ' /force'
    Return $sComString
EndFunc   ;==>_GetComString

Func _BootSect()
    GUICtrlSetState($iBtnStart, $GUI_DISABLE)
    Local $iPID, $sOut, $tmp, $sComString = _GetComString()
    If @error Then
        GUICtrlSetData($iStatusBar, $Lng[21])
        Return SetError(1, 0, $Lng[21])
    EndIf

    $iPID = Run('"' & $sPathBootSect & '"' & $sComString, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
    While 1
        $tmp = StdoutRead($iPID)
        If @error Then ExitLoop
        If $tmp Then $sOut &= @CRLF & $tmp
    WEnd
    GUICtrlSetState($iBtnStart, $GUI_ENABLE)
    If StringInStr($sOut, 'successfully') Then GUICtrlSetData($iStatusBar, GUICtrlRead($iStatusBar) & '   ' & $Lng[15])
    ; Return SetError($tmp, 0, $sOut)
    $sOut = $Lng[16] & @CRLF & _
            'Path: ' & @TAB & $sPathBootSect & @CRLF & _
            'ComString: ' & @TAB & $sComString & @CRLF & @CRLF & _
            $Lng[17] & @CRLF & _
            $sOut & @CRLF & _
            $Lng[18]
    Return $sOut
EndFunc   ;==>_BootSect

Func _Help()
    Local $iPID, $sOut, $tmp
    $iPID = Run('"' & $sPathBootSect & '" /help', @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
    While 1
        $tmp = StdoutRead($iPID)
        If @error Then ExitLoop
        If $tmp Then $sOut &= @CRLF & $tmp
    WEnd
    Return $sOut
EndFunc   ;==>_Help

Func _Viewing($hGUI, $sLog)
    Local $hGuiLog, $aRect, $iEdit
    $aRect = _GetChildCoor($hGUI, 560, 330)
    GUISetState(@SW_DISABLE, $hGUI)

    $hGuiLog = GUICreate($Lng[19], $aRect[0], $aRect[1], $aRect[2], $aRect[3], BitOR($WS_OVERLAPPEDWINDOW, $WS_POPUP), -1, $hGUI)
    If Not @Compiled Then GUISetIcon(@ScriptDir & '\BootSectGui.ico')

    $iEdit = GUICtrlCreateEdit('', 0, 0, $aRect[0], $aRect[1])

    GUISetState(@SW_SHOW, $hGuiLog)

    GUICtrlSetData($iEdit, $sLog)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUISetState(@SW_ENABLE, $hGUI)
    GUIDelete($hGuiLog)
EndFunc   ;==>_Viewing

Func _GetDrv()
    Local $sInfo = _ComboListDrive('Fixed')
    $sInfo &= _ComboListDrive('Removable')
    Return StringTrimLeft($sInfo, 1)
EndFunc   ;==>_GetDrv

Func _ComboListDrive($Type) ; coded by AZJIO (2013.01.26)
    Local $aDrive = DriveGetDrive($Type), $list = '', $sString, $sLabel, $aDisc_Partition
    If @error Then Return ''
    If $Type = 'Removable' Then $Type = 'Rem'
    For $i = 1 To $aDrive[0]
        If $aDrive[$i] = 'A:' Then ContinueLoop
        $sLabel = DriveGetLabel($aDrive[$i])
        If StringLen($sLabel) > 15 Then $sLabel = StringLeft($sLabel, 12) & '...'
        $aDisc_Partition = _GetDiskNimberForDrive($aDrive[$i])
        ; If @error Then Local $aDisc_Partition[2] = ['?', '?']
        $sString = StringFormat('%2s:%-2s %-2s %-5s %-15s %-5s ', $aDisc_Partition[0], $aDisc_Partition[1], StringUpper($aDrive[$i]), $Type, $sLabel, _
                DriveGetFileSystem($aDrive[$i])) & _GetSize(DriveSpaceTotal($aDrive[$i])) & ' ' & $Lng[20]
        $list &= $sp & $sString
    Next
    Return $list
EndFunc   ;==>_ComboListDrive

Func _GetSize($s) ; coded by AZJIO
    $s = StringFormat('%.03f', $s / 1024)
    If StringLen($s) > 7 Then $s = StringRegExpReplace(StringTrimRight($s, 4), '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ') & StringRight($s, 4)
    Return StringFormat('%9s', $s) ; 9 терабайт
EndFunc   ;==>_GetSize

Func _AddDash($s, $i, ByRef $sWord)
    If Not StringIsDigit($i) Then Return
    Local $iLen = StringLen($sWord)
    If $iLen > $i - 2 Then Return
    $i = Int(($i - $iLen) / 2)
    Local $sDash = StringReplace(StringFormat('%0' & $i & 'd', '0'), '0', $s, 0, 2)
    $sWord = $sDash & ' ' & $sWord & ' ' & $sDash
EndFunc   ;==>_AddDash


; http://www.autoitscript.com/forum/topic/91598-get-disk-number-from-drive-letter/?p=659721
; Описание ........: Возвращает номер диска и номер раздела в формате n:n (<номер диска>:<номер раздела>)
; Параметры:
;       $sDriveLetter - Буква диска с двоеточием, например C:
;                   Неудачно , возвращает -1, @error:
;                  |1 - Ошибка CreateFile, ваша система очень старая
;                  |2 - Диск не существует
;                  |3 - Неудачный вызов DeviceIoControl
;                  |4 - Не раздела диска
Func _GetDiskNimberForDrive($sDriveLetter) ; Буква диска

    Local $aDrive[2] = ['?', '?']

    Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _
            "str", "\\.\" & $sDriveLetter, _; Буква диска
            "dword", 0, _
            "dword", 0, _
            "ptr", 0, _
            "dword", 3, _; OPEN_EXISTING
            "dword", 128, _; FILE_ATTRIBUTE_NORMAL
            "ptr", 0)

    If @error Then
        Return SetError(1, 0, $aDrive); Ваша система очень старая. Сделайте что-нибудь.
    EndIf

    If $a_hCall[0] = -1 Then
        Return SetError(2, 0, $aDrive) ; Диск не существует
    EndIf

    Local $hDevice = $a_hCall[0]

    Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _
            "dword DeviceNumber;" & _
            "int PartitionNumber")

    Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _
            "hwnd", $hDevice, _
            "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER
            "ptr", 0, _
            "dword", 0, _
            "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
            "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
            "dword*", 0, _
            "ptr", 0)

    If @error Or Not $a_hCall[0] Then
        DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)
        Return SetError(3, 0, $aDrive); неудачный вызов DeviceIoControl
    EndIf

    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)

    If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK
        $aDrive[0] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")
        $aDrive[1] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber")
        Return SetError(0, 0, $aDrive)
    EndIf

    Return SetError(4, 0, $aDrive); Не раздела диска

EndFunc   ;==>_GetDiskNimberForDrive

Func _GetPath($sFile)
    Local $tmp = _WinAPI_PathFindOnPath($sFile, @ScriptDir)
    If Not @error Then Return $tmp
    ; Теоритически эти пути уже есть в %PATH%, но проверим ещё раз
    If FileExists(@SystemDir & '\' & $sFile) Then
        Return @SystemDir & '\' & $sFile
    ElseIf FileExists(@WindowsDir & '\' & $sFile) Then
        Return @WindowsDir & '\' & $sFile
    EndIf
    Return SetError(1)
EndFunc   ;==>_GetPath
Edited by AZJIO
Link to comment
Share on other sites

I apologize for my late reply.

@AZJIO

Great improvement!  :thumbsup:  You have done far more than I can hope to do. Thank you! I had to change one thing you changed, because I saw nothing happened in the BooSectLog window:

$iPID = Run(@ComSpec & ' /c "' & $sPathBootSect & '" ' & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce, @ScriptDir, @SW_HIDE, $STDIN_CHILD)
     For:
$iPID = Run(@ComSpec & ' /c "' & $sPathBootSect & '" ' & $sBootCode & " " & $sBootSectDrive & $sMBR & $sForce, @ScriptDir, @SW_HIDE, "0x2")
 
Why your change doesn't work? I don't know. I found my code in internet years ago. I can't give credit because at that time I didn't keep URL.

 

Your BootSectGui is more complex than mine and very interresting. The code needs UserGUI.au3 to work.

MDV

Mad Dog (Maurice) Vachon, a great Canadian professional wrestler!

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

×
×
  • Create New...