Jump to content
Sign in to follow this  
MadDogVachon

BootSectGui x64

Recommended Posts

MadDogVachon

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!

Share this post


Link to post
Share on other sites
JFX

Hi MadDogVachon,

your tool updating the partition boot code or sometimes called the volume boot code.
To updated the master boot code you will need to also pass the /mbr switch to bootsect.exe.

Share this post


Link to post
Share on other sites
MadDogVachon

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!

Share this post


Link to post
Share on other sites
JFX

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.

Share this post


Link to post
Share on other sites
MadDogVachon

@ 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!

Share this post


Link to post
Share on other sites
AZJIO

@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

Share this post


Link to post
Share on other sites
MadDogVachon

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!

Share this post


Link to post
Share on other sites
AZJIO

MadDogVachon

$STDIN_CHILD = 0x1

$STDOUT_CHILD = 0x2

I made a mistake in a "Const". I was too lazy to fix. I completely rewrote the script. See the link (Post #7)

Edited by AZJIO

Share this post


Link to post
Share on other sites
MadDogVachon

@AZJIO

Thanks!

I added version 1.2.1. It has AZJIO improvement of the code except for querying drives. That's the first and simple way of listing drives. See the look: https://db.tt/aeEDzT7u

MDV

Edited by MadDogVachon

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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • ModemJunki
      By ModemJunki
      Hello,
      I solved it - only had to add a sleep for 10 seconds or so to make sure the shell could see the I.P. address change.
      I'm working in Windows PE environment (10.0.10586). I think I have some permissions issue related to AutoIT
      I've tried with Net Share and with DriveMapAdd - neither work.
      So finally I made the script output a batch file with a pause and what I found is that in WinPE, the batch file behaves differently if it's run at the command prompt or if it is spawned by AutoIT.
      If spawned by AutoIT, the net use command gives error 1231 "The network location cannot be reached". I assume this is the same problem that DriveMapAdd is having.
      But if I run the same batch file under the command shell in the Windows PE instance, it works.
      I also made a simple test with Ping() and it always returns 1 (host is offline) but I can ping it from the command line in the same PE session.
      Are there service dependencies for this to work? What is preventing AutoIT from accessing the network?
      Below sample is kind of dirty but illustrates what I'm doing. Could use a lot more refinement for error checking etc.
      ;~ #RequireAdmin #include <Array.au3> #include <AutoItConstants.au3> _SetUpPEIP() Func _SetUpPEIP() Local $s_user = "USER" Local $s_pass = "PASS" Local $s_RMTIP = "10.1.1.4" Local $s_RMTSHR = "SHARED_FOLDER" Local $s_IPPrefix = "10.1.1." Local $s_netMask = "255.255.255.0" Local $s_StartIP = 20 Local $a_NICs[1] Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL") If IsObj($colItems) Then ; gather network card names For $objItem In $colItems If $objItem.NetConnectionStatus == "2" Or $objItem.NetConnectionStatus == "9" Then _ArrayAdd($a_NICs, $objItem.NetConnectionID) EndIf Next EndIf If IsArray($a_NICs) Then ; assign them I.P. addresses For $i = 1 To UBound($a_NICs) - 1 $s_setIP = "netsh interface IP set address name=""" & $a_NICs[$i] & """ static " & $s_IPPrefix & $i + $s_StartIP - 1 & " " & $s_netMask $s_ipRes = RunWait(@ComSpec & " /c " & $s_setIP, @ScriptDir, @SW_HIDE) ; expect 0 Sleep(100) ConsoleWrite($s_setIP & " result is: " & $s_ipRes & @CRLF) Next Sleep(10000) ; wait for the shell to catch up and enum the I.P. $sres = DriveMapAdd("Z:", "\\" & $s_RMTIP & "\" & $s_RMTSHR, $DMA_PERSISTENT, $s_user, $s_pass) ; now map a drive Else ; error! No cards found! EndIf EndFunc ;==>_SetUpPEIP  
    • RTFC
      By RTFC
      Please answer me these questions three, ere the other side you see:
      Are you running a 64-bit machine with a 64-bit Windows operating system? Can your AutoIt scripts cope with having directive #AutoIt3Wrapper_UseX64=Y, and thus @AutoItX64=True? Are you sick and tired of seeing this error message?
      If you (like me) answered "YES" to all three questions, then the _HighMem library may ease your pain (the name commemorates a useful utility from the days when CPUs were still steam-powered). Forget about pathetic boot switches /3GB and /userva; in a full-fledged 64-bit environment, _HighMem can pre-allocate all available physical/virtual RAM you've got (or any smaller size you need), and manage individual allocations therein with four simple functions:
      _HighMem_StartUp( $nSize, $sUnit="GB" ) ; parse size of total region to pre-allocate, e.g. (10,"GB") _HighMem_Allocate( $nSize, $sUnit="B" ) ; returns $pOffset (new allocation's base address) _HighMem_Release( $pOffset ) ; existing allocations are identified by their offset (base address) _HighMem_CleanUp() ; close handles, release all pre-allocated memory Of course, existing AutoIt limitations remain in force (e.g., DllstructCreate() is still limited to 2 GB per call), but the maximum of 2-4 GB of virtual memory per Windows process can (under the right circumstances, in the proper environment) be circumvented. However, this is the first beta release, so glitches are likely, and performance may vary. In fact, it may not work at all for you (if you're running 32-bit, for example). And since this involves your own hardware, it's unlikely I would be able to reproduce your issues in my own work environment. Nevertheless, if you find obvious bugs or mistakes in the code, please do post. And if it works for you, that's also good to hear. My own motivation for developing it was to supercharge my matrix computing environment (Eigen4AutoIt), so it can handle matrices of any size that fit in machine RAM.
      The attached zip contains the library itself (HighMem.au3) and two test examples. HighMem_Test1 performs a dry run stress test of the allocation management system; it does not actually do any memory I/O. By contrast, HighMem_Test2 pre-allocates a 6 GB space, stores 3 x 2GB structs there, performs some basic I/O, and releases the allocations one by one. Obviously, for this to work you'll need at least that much free RAM to begin with (check with Task Manager -> Performance -> Memory if you're unsure). My own test environment has 16 GB of physical RAM, and runs W10Pro/64.
      EDIT: minor edits added to improve user experience (many more status messages if $_HighMem_Verbose=True)
      HighMem.v0.85.7z
      EDIT: from beta version 0.9, HighMem supports shared memory, including mutex negotiation.
       
      HighMem.v0.91.7z
    • iXX
      By iXX
      Hi!
      Looking for working code to  get full path of process  - both 32 & 64 bit.
      I tryed this bellow, but it works only for 32-bit processes, even if compiled for x64...
      Thanx for suggestions!
       
      Func _ProcessGetPath($vProcess) ;get the program path done by MrCreatoR Local $iPID = ProcessExists($vProcess) If NOT $iPID Then Return SetError(1, 0, -1) Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If NOT IsArray($aProc) OR NOT $aProc[0] Then Return SetError(2, 0, -1) Local $vStruct = DllStructCreate('int[1024]') Local $hPsapi_Dll = DllOpen('Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll') If $hPsapi_Dll = -1 Then Return SetError(3, 0, '') DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _ 'hwnd', $aProc[0], _ 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), _ 'int_ptr', 0) Local $aRet = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) DllClose($hPsapi_Dll) If NOT IsArray($aRet) OR StringLen($aRet[3]) = 0 Then Return SetError(4, 0, '') Return $aRet[3] EndFunc  
    • mdwerne
      By mdwerne
      I'm attempting to cobble together a replacement for the 64bit version of BGInfo that will run within WinPE 10/64. I've located a couple useful threads:
       Between the two, they get me close (see code below), but for some reason GDI+ is not working the same within WinPE as it does in Windows 10. Bottomline is that the "Text" never get's written to WallPaper.
      Here is what I have thus far. Any thoughts if any of the GDI commands might not work within WinPE? Any other way to achieve the same result (system information on the wallpaper in WinPE 10)?
      #include <GDIPlus.au3> #include <Date.au3> _GDIPlus_Startup() $image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\WallPaper.bmp") $imagegraphics = _GDIPlus_ImageGetGraphicsContext($image) $w = _GDIPlus_ImageGetWidth($image) $h = _GDIPlus_ImageGetHeight($image) $whitebrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $fontfamily = _GDIPlus_FontFamilyCreate("Arial") $font = _GDIPlus_FontCreate($fontfamily, 16) $stringformat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($stringformat, 2) $rect = _GDIPlus_RectFCreate(0, $h - $h + 100, $w - 25, $h) ;$rect = _GDIPlus_RectFCreate(100, 100, 200, 200) _GDIPlus_GraphicsDrawStringEx($imagegraphics, _Now() & @CRLF & @UserName & @CRLF & @ComputerName & @CRLF & @IPAddress1, $font, $rect, $stringformat, $whitebrush) _GDIPlus_ImageSaveToFile($image, @ScriptDir & "\NewWallPaper.bmp") _GDIPlus_ImageDispose($image) _GDIPlus_GraphicsDispose($imagegraphics) _GDIPlus_BrushDispose($whitebrush) _GDIPlus_FontFamilyDispose($fontfamily) _GDIPlus_FontDispose($font) _GDIPlus_StringFormatDispose($stringformat) _GDIPlus_Shutdown() _ChangeDesktopWallpaper(@ScriptDir & "\NewWallPaper.bmp", 2) Func _ChangeDesktopWallpaper($bmp, $style = 0) ;=============================================================================== ; ; Function Name: _ChangeDesktopWallPaper ; Description: Update WallPaper Settings ; Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp',1) ; Parameter(s): $bmp - Full Path to BitMap File (*.bmp) ; [$style] - 0 = Centered, 1 = Tiled, 2 = Stretched ; Requirement(s): None. ; Return Value(s): On Success - Returns 0 ; On Failure - -1 ; Author(s): FlyingBoz ; Thanks: Larry - DllCall Example - Tested and Working under XPHome and W2K Pro ; Excalibur - Reawakening my interest in Getting This done. ; ;=============================================================================== If Not FileExists($bmp) Then Return -1 ;The $SPI* values could be defined elsewhere via #include - if you conflict, ; remove these, or add if Not IsDeclared "SPI_SETDESKWALLPAPER" Logic Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 Local $REG_DESKTOP = "HKEY_CURRENT_USER\Control Panel\Desktop" If $style = 1 Then RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 1) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", $style) EndIf DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $bmp, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) Return 0 EndFunc ;==>_ChangeDesktopWallpaper Thanks for your time,
      -Mike
    • czyt
      By czyt
       
      May it helps those who needed.
       
      #include <WinAPI.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsUEFIBoot ; Description ...: Detemine the Current OS is boot in UEFI mode or not ; Syntax ........: _IsUEFIBoot() ; Parameters ....: ; Return values .: True:OS is boot in UEFI ; False: OS is boot in Legacy BIOS ; Author ........: czyt ; Modified ......: ; Remarks .......: ; Related .......: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/DllCall~Information+Booted~UEFI~or~BIOS.txt ; Link ..........: ; Example .......: MsgBox(0,'(*^__^*) The OS is in UEFI Boot mode?',_IsUEFIBoot()) ; =============================================================================================================================== Func _IsUEFIBoot() Local Const $ERROR_INVALID_FUNCTION=0x1 DllCall("Kernel32.dll", "dword", "GetFirmwareEnvironmentVariableW", "wstr", "", "wstr", '{00000000-0000-0000-0000-000000000000}', "wstr", Null, "dword", 0) If _WinAPI_GetLastError() = $ERROR_INVALID_FUNCTION Then Return False Else Return True EndIf EndFunc  
×