bobomb Posted December 4, 2021 Share Posted December 4, 2021 (edited) I am making a basic GUI for Diskpart using examples I have found across your forum, for the purpose of preparing a hard drive for WinNTSetup5. It will format the selected drive in your choice of either MBR or GPT layout then edit WinNTSetup.ini and add the appropriate drive letters to simplify using WinNTSetup5 to install windows. With this GUI you simply select your layout and when WinNTSetup5 opens you just pick your ISO, edition, then click setup.. Otherwise you would have to manually format everything correctly etc, it is tedious to say the least. You place it in a subfolder with a name of your choosing of WinNTSetup5 (e.g. WinNTSetup5\Prep) and it will traverse up one level to edit\create the INI settings with the correct drive letters. (This file is to be created by the user with intended settings, per the authors instruction.) After testing hundreds of formats on diff style drives, internal and external I found breaking up the diskpart commands, even though recommended against by microsoft, it works every time and not as a single diskpart script.. (idk why this is true?) With that long winded explanation out of the way, the below code works perfectly fine. But I am wondering if there is an easy way to move the GUI out of the _SelectDrive function so I can be a little more versatile with this. I'm not sure if there is even a problem with it but it feels like a large part of the program is nested in a function and it shouldnt be? I am a beginner, I know its ugly, advice or examples very much appreciated ***This WILL format the selected drive if you tell it to. Use caution if you test it. expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> $listiniFile = (@WorkingDir & '\cache\list.ini') $listtxtFile = (@WorkingDir & '\cache\list.txt') $File = "" $bootDrive = "" $mainDrive = "" $driveletter = StringSplit("C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z",",",1) _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'list disk') FileClose($listFile) RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 _SelectDrive() Func _SelectDrive() Local $Menu1, $n1, $n2, $n3, $Msg, $Menustate, $Menutext Local $Line, $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $i = 0 To UBound($Array) - 1 If StringRegExp($Array[$i], '(?i)Disk [\d]+') Then $Line &= $Array[$i] & '|' Next $Line = StringRegExpReplace($Line, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string GUICreate('Prep/Format Disk v1.1', 300, 277) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $n1 = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Line) GUICtrlCreateLabel('2: Select your desired layout...', 20, 187, 280, 30) $n2 = GUICtrlCreateButton('BIOS (MBR) Boot',20, 205, 120, 40) $n3 = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 205, 120, 40) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 251, 130, 30) GUISetState() _GetDriveLetters() Do $Msg = GUIGetMsg() If $Msg = $n2 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Msg = $n3 Then Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf Until $Msg = $GUI_EVENT_CLOSE _Cleanup() EndFunc ;==>_SelectDrive (MAIN) Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileWrite($scrubdatFile, @CRLF & 'clean') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Setting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, @CRLF & 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(20 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() For $i = 1 to $driveletter[0] step +1 $var = DriveStatus( $driveletter[$i] & ":" ) If $var = "INVALID" Then $bootDrive=($driveletter[$i]) For $i = 1 to $driveletter[0] step +1 $var = DriveStatus( $driveletter[$i] & ":" ) If $var = "INVALID" Then $mainDrive=($driveletter[$i]) EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters Edited December 18, 2021 by bobomb meoit 1 Link to comment Share on other sites More sharing options...
Solution mikell Posted December 4, 2021 Solution Share Posted December 4, 2021 26 minutes ago, bobomb said: I'm not sure if there is even a problem with it but it feels like a large part of the program is nested in a function It's absolutely NOT a problem. Did you notice that in most examples in the help file, the main script is nested in a single Main() function ? BTW as you call the _SelectDrive() func only once, it doesn't seem very useful. Make its whole content the main code (using no func) is the easiest way I can think of to get the GUI out of a func Link to comment Share on other sites More sharing options...
bobomb Posted December 4, 2021 Author Share Posted December 4, 2021 (edited) Lol, so to remove the function here all I need to do is remove the call to, and the open/close of the function, haha. I feel dumber than normal right now Thank You Do I still need to use Local to declare the variables if it is no longer in a function? Edited December 4, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 4, 2021 Author Share Posted December 4, 2021 (edited) Again thank you. This would be the final au3 with those minor changes, and some variable cleanup. expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 Global $Filtered, $DiskList, $MBR, $GPT, $Selection, $bootDrive, $mainDrive, $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string GUICreate('Prep/Format Disk v1.1', 300, 277) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Filtered) GUICtrlCreateLabel('2: Select your desired layout...', 20, 187, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 205, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 205, 120, 40) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 251, 130, 30) GUISetState() _GetDriveLetters() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters (Also, thanks @Musashi for the simple yet elegant, if(not)/then logic that I could not bring myself to think of 😜) Edited December 4, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) Is refreshing the GUI list possible with this? I Saw references to GUICtrlUpdate... but when I click the links references to it are not there. I probably have to: RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string Add that again by putting it in its own function to actually update the variable values. But actually refreshing the GUICtrlSetData(?) idk Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 Hmm... I have this now. expandcollapse popup#NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=PrepareDiskNT.ico #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Run from WinNTSetup5\Prep Folder #AutoIt3Wrapper_Res_Description=PrepareDiskNT #AutoIt3Wrapper_Res_Fileversion=1.1.0.0 #AutoIt3Wrapper_Add_Constants=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $MBR, $GPT, $Refresh, $Selection, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) _LoadGUI() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then GUIDelete() _LoadGUI() EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _LoadGUI() RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 Local $RawList, $Filtered, $Disklist, $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string GUICreate('Prep/Format Disk v1.1', 300, 277) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Filtered) GUICtrlCreateLabel('2: Select your desired layout...', 20, 187, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 205, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 205, 120, 40) GUICtrlSetState(-1, $GUI_FOCUS) $Refresh = GUICtrlCreateButton('Refresh', 270, 1, 27, 27) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 251, 130, 30) GUISetState() _GetDriveLetters() EndFunc ;==> _LoadMenu Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters However it reloads the entire gui. Is there a way to only refresh the gui list without refreshing the entire gui from the version i posted before this? Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) I apologize for posting so much. That last edit was bugged. but here it is finished and working, again this reloads the entire GUI and I am curious if there is a better way to refresh/reload only the list inside the existing GUI without reloading the entire thing.. expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $MBR, $GPT, $Refresh, $Selection, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) _LoadGUI() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then GUIDelete() _LoadGUI() EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _LoadGUI() RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 Local $RawList, $Filtered, $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string GUICreate('Prep/Format Disk v1.1', 300, 298) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Filtered) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() _GetDriveLetters() EndFunc ;==> _LoadGUI Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters GUI back into a function right where i started lol... At least everything is working and I have a functional refresh button now.. Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
junkew Posted December 5, 2021 Share Posted December 5, 2021 All you need to do somewhere instead of -1 refer to the name of the control GUICtrlSetData($diskList, $Filtered) bobomb 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) @junkew That doesnt clear the array it keeps adding duplicates each time the refresh button is pressed. How do you clear the array listed before you readd the information Example (I Switched to this format to try your method): expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $Filtered, $RawList, $Array, $Selection, $MBR, $GPT, $Refresh, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) _GetInfo() GUICreate('Prep/Format Disk v1.2', 300, 298) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Filtered) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then _GetInfo() GUICtrlSetData($DiskList, $Filtered) EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _GetInfo() RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string _GetDriveLetters() EndFunc ;==>_GetInfo Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() Local $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters It says in the help file if the data is not "" it will be dropped into the entry point.. At the end? The variable def doesnt = "" that we are adding.. EDIT*: I accidentally had quotes around the $Filtered variable so i reposted the code without them to fix the example to repeat the issue. Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
benners Posted December 5, 2021 Share Posted December 5, 2021 The issue is most likely the $Filtered value and this line $Filtered &= $Array[$RawList] & '|' You aren't clearing the $Filtered value each time you read the file so previous values get added as well when using "&=" Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) @junkew Thanks, @benners The filtered value needed to be cleared. But I also needed to add GUICtrlSetData($DiskList, "") to clear the original list data or it would append. This works now expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $Filtered, $RawList, $Array, $Selection, $MBR, $GPT, $Refresh, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) _GetInfo() GUICreate('Prep/Format Disk v1.2', 300, 298) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, $Filtered) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then $Filtered = "" _GetInfo() GUICtrlSetData($DiskList, "") GUICtrlSetData($DiskList, $Filtered) EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _GetInfo() RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string _GetDriveLetters() EndFunc ;==>_GetInfo Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() Local $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters And i managed to get that GUI out of the function like I was originally trying to do.. Thanks you everyone for all of your help.. Well refreshing a GUI list, I'm sure there are other ways but it is very easy to follow using this method. Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
benners Posted December 5, 2021 Share Posted December 5, 2021 You can do it all in the _GetInfo function. One less global var ($Filtered) and just return the value for the list. expandcollapse popupGlobal $DiskList, $RawList, $Array, $Selection, $MBR, $GPT, $Refresh, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) _GetInfo() GUICreate('Prep/Format Disk v1.2', 300, 298) GUISetIcon(@WorkingDir & '\PrepareDiskNT.ico', 1) GUISetBkColor(0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, '') $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot', 20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then GUICtrlSetData($DiskList, _GetInfo()) Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _GetInfo() Local $Filtered = '' RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string _GetDriveLetters() Return $Filtered EndFunc ;==>_GetInfo Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...", "Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...", "Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite("..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":") EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite("..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":") EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() Local $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C", ",", 1) For $bd = 1 To $driveletter[0] Step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive = ($driveletter[$bd]) For $md = 1 To $driveletter[0] Step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive = ($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive = ($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters bobomb 1 Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 That recreates the initial issues of the list not clearing it also stops the list from appearing initially until the refresh button is pressed, I dont quite understand it enough to manipulate what you are showing me to my needs unfortunately but I kind of understand it. Same as everyone else I am teaching myself other than the help I am afforded. You guys a great here I'm sure you get tons of beginner questions or people asking you to write code FOR them and I know that can be frustrating. Link to comment Share on other sites More sharing options...
benners Posted December 5, 2021 Share Posted December 5, 2021 To get it to show initially you can run the _GetInfo function when you create the list. I commented the first run of _GetInfo out. Don't know if it is needed before the list control is created. I don't get the list clearing issues when I keep refreshing as I did previously. I only have one drive in this puter though. expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $RawList, $Array, $Selection, $MBR, $GPT, $Refresh, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) ;~ _GetInfo() GUICreate('Prep/Format Disk v1.2', 300, 298) GUISetIcon(@WorkingDir & '\PrepareDiskNT.ico', 1) GUISetBkColor(0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList(_GetInfo(), 20, 30, 260, 150) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot', 20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then GUICtrlSetData($DiskList, _GetInfo()) Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _GetInfo() Local $Filtered = '' RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string _GetDriveLetters() Return $Filtered EndFunc ;==>_GetInfo Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...", "Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...", "Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite("..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":") EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite("..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":") IniWrite("..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":") EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() Local $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C", ",", 1) For $bd = 1 To $driveletter[0] Step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive = ($driveletter[$bd]) For $md = 1 To $driveletter[0] Step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive = ($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive = ($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters bobomb 1 Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) Unfortunately That breaks the Array list. Instead of Breaking at "|" it continues the line to the right instead of a new line... I see what you are trying to do i do not know why it breaks the list though. The different approaches in AutoIT3 are neat 😜 Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) @benners I got this working using your method (Formatting - retrieving list data failed now GUICtrlRead($DiskList... expandcollapse popup#NoTrayIcon #RequireAdmin #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ListBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $RawList, $Array, $Selection, $MBR, $GPT, $Refresh, $bootDrive, $mainDrive _Cleanup() DirCreate(@WorkingDir & '\cache') $listFile = FileOpen(@WorkingDir & '\cache\list.ini', 2) FileWrite($listFile, 'lis dis') FileClose($listFile) GUICreate('Prep/Format Disk v1.2', 300, 298) GUISetIcon (@WorkingDir & '\PrepareDiskNT.ico',1) GUISetBkColor (0x797979) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup5', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150) GUICtrlSetData(-1, _GetInfo()) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $MBR = GUICtrlCreateButton('BIOS (MBR) Boot',20, 232, 120, 40) $GPT = GUICtrlCreateButton('UEFI (GPT) Boot', 160, 232, 120, 40) GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() Do $Selection = GUIGetMsg() If $Selection = $MBR Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatMBR($DiskN[6]) _IniWriteMBR() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $bootDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $GPT Then Local $Disk = StringRegExpReplace(GUICtrlRead($DiskList), '(?i)^.*(Disk [\d]+).*$', '$1') Local $DiskN = StringSplit($Disk, "") Local $iMsgBoxAnswer If $Disk = "" Then MsgBox($MB_ICONERROR, "Notice: ", "No disk has been selected") Else $iMsgBoxAnswer = MsgBox(262452, 'This will FORMAT Disk ' & $DiskN[6], 'ALL DATA WILL BE ERASED FROM ' & 'DISK ' & $DiskN[6] & @CRLF & 'Are you sure you want to proceed?') Select Case $iMsgBoxAnswer = 6 ;Yes _FormatGPT($DiskN[6]) _IniWriteGPT() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup5 will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $bootDrive & @CRLF & 'Install Drive: ' & $mainDrive) Run("cmd /c ..\WinNTSetup_x64.exe", @WorkingDir, @SW_HIDE) _Cleanup() Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndIf EndIf If $Selection = $Refresh Then GUICtrlSetData($DiskList, "") GUICtrlSetData($DiskList, _GetInfo()) EndIf Until $Selection = $GUI_EVENT_CLOSE _Cleanup() Func _GetInfo() $Filtered = '' RunWait("cmd /c diskpart /s cache\list.ini>cache\list.txt", @WorkingDir, @SW_HIDE) ; Only works when compiled if x64 $Array = _StringExplode(FileRead(@WorkingDir & '\cache\list.txt'), @LF) For $RawList = 0 To UBound($Array) - 1 If StringRegExp($Array[$RawList], '(?i)Disk [\d]+') Then $Filtered &= $Array[$RawList] & '|' Next $Filtered = StringRegExpReplace($Filtered, '[\s|]*$', '') ;Removal of spaces, returns, line breaks, and pipes from end of the string Return $Filtered _GetDriveLetters() EndFunc ;==>_GetInfo Func _FormatMBR($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=MBRscrubber') FileClose($scrubdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert mbr') FileClose($convertFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'format quick fs=NTFS label=Windows') FileWrite($mainFile, @CRLF & 'Active') FileWrite($mainFile, @CRLF & 'Assign letter=' & $bootDrive) FileClose($mainFile) ProgressOn("Getting BIOS (MBR) Ready...","Preparing Disk: ", "0%") ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(30 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(40 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(50 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(60 & "%", "Converting Disk Layout to MBR") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatMBR Func _FormatGPT($Drive) GUISetState(@SW_HIDE) $cleandatFile = FileOpen(@WorkingDir & '\cache\clean.dat', 2) FileWrite($cleandatFile, 'Sel Dis ' & $Drive) FileWrite($cleandatFile, @CRLF & 'clean') FileClose($cleandatFile) $scrubdatFile = FileOpen(@WorkingDir & '\cache\scrub.dat', 2) FileWrite($scrubdatFile, 'Sel Dis ' & $Drive) FileWrite($scrubdatFile, @CRLF & 'cre par pri') FileWrite($scrubdatFile, @CRLF & 'format quick fs=NTFS label=GPTscrubber') FileClose($scrubdatFile) $attribdatFile = FileOpen(@WorkingDir & '\cache\attrib.dat', 2) FileWrite($attribdatFile, 'Sel Dis ' & $Drive) FileWrite($attribdatFile, @CRLF & 'attribute disk clear readonly') FileClose($attribdatFile) $convertFile = FileOpen(@WorkingDir & '\cache\convert.dat', 2) FileWrite($convertFile, 'Sel Dis ' & $Drive) FileWrite($convertFile, @CRLF & 'convert gpt') FileClose($convertFile) $fsFile = FileOpen(@WorkingDir & '\cache\formatsystem.dat', 2) FileWrite($fsFile, 'Sel Dis ' & $Drive) FileWrite($fsFile, @CRLF & 'cre par efi size=100') FileWrite($fsFile, @CRLF & 'format quick fs=fat32 label=System') FileWrite($fsFile, @CRLF & 'assign letter=' & $bootDrive) FileClose($fsFile) $msrFile = FileOpen(@WorkingDir & '\cache\createmsr.dat', 2) FileWrite($msrFile, 'Sel Dis ' & $Drive) FileWrite($msrFile, @CRLF & 'cre par msr size=16') FileClose($msrFile) $mainFile = FileOpen(@WorkingDir & '\cache\formatmain.dat', 2) FileWrite($mainFile, 'Sel Dis ' & $Drive) FileWrite($mainFile, @CRLF & 'cre par pri') FileWrite($mainFile, @CRLF & 'shrink minimum=450') FileWrite($mainFile, @CRLF & 'format quick fs=ntfs label=Windows') FileWrite($mainFile, @CRLF & 'assign letter=' & $mainDrive) FileClose($mainFile) $reFile = FileOpen(@WorkingDir & '\cache\formatwinre.dat', 2) FileWrite($reFile, 'Sel Dis ' & $Drive) FileWrite($reFile, @CRLF & 'cre par pri') FileWrite($reFile, @CRLF & 'format quick fs=ntfs label=WinRE') FileWrite($reFile, @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac') FileClose($reFile) ProgressOn("Getting UEFI (GPT) Ready...","Preparing Disk: ", "0%") ProgressSet(10 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(15 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\scrub.dat", @WorkingDir, @SW_HIDE) SLEEP(1000) ProgressSet(20 & "%", "Cleaning Drive") RunWait("cmd /c diskpart /s cache\clean.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(30 & "%", "Resetting Disk Attributes") RunWait("cmd /c diskpart /s cache\attrib.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(40 & "%", "Converting Disk to GPT") RunWait("cmd /c diskpart /s cache\convert.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(50 & "%", "Formatting System Partition") RunWait("cmd /c diskpart /s cache\formatsystem.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(70 & "%", "Creating MSR") RunWait("cmd /c diskpart /s cache\createmsr.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(80 & "%", "Formatting Windows Partition") RunWait("cmd /c diskpart /s cache\formatmain.dat", @WorkingDir, @SW_HIDE) Sleep(1000) ProgressSet(90 & "%", "Formatting WinRE Partition") RunWait("cmd /c diskpart /s cache\formatwinre.dat", @WorkingDir, @SW_HIDE) ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>_FormatGPT Func _IniWriteMBR() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $bootDrive & ":" ) EndFunc ;==>_IniWriteMBR Func _IniWriteGPT() IniWrite ( "..\WinNTSetup.ini", "WinNT6", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT6", "TempDest", $mainDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "BootDest", $bootDrive & ":" ) IniWrite ( "..\WinNTSetup.ini", "WinNT5", "TempDest", $mainDrive & ":" ) EndFunc ;==>_IniWriteGPT Func _Cleanup() Local Const $WDcachePath = @WorkingDir & "\cache" If FileExists($WDcachePath) Then DirRemove($WDcachePath, $DIR_REMOVE) EndIf EndFunc ;==>_Cleanup Func _GetDriveLetters() Local $driveletter = StringSplit("Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C",",",1) For $bd = 1 to $driveletter[0] step +1 $bdStat = DriveStatus($driveletter[$bd] & ":") If $bdStat = "INVALID" Then $bootDrive=($driveletter[$bd]) For $md = 1 to $driveletter[0] step +1 $mdStat = DriveStatus($driveletter[$md] & ":") If Not ($bootDrive=($driveletter[$md])) Then If $mdStat = "INVALID" Then $mainDrive=($driveletter[$md]) EndIf EndIf Next EndIf Next EndFunc ;==>_GetDriveLetters If I do not first: GUICtrlSetData($DiskList, "") Before updating the list it only appends to the list... I have to do the above to clear it first. But it is working this way too Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) I think we are ok, thats last update breaks the GUICtrlRead($DiskList) when the disk is selected. nbd I really do appreciate all the help(only noted for others who are looking at copying it out for their own use), A previous version in this thread works great. your ideas already helped with that so Thanks again. Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
benners Posted December 5, 2021 Share Posted December 5, 2021 No problem about the help. I have used this forums loads myself. Looking at the last code, there a couple of things. A good habit to get into is declaring the scope of variables. This is good practice. There is information in the wiki that is useful. each to their own really but I try to have as few globals as possible, as long as it's not more convoluted in doing so. The other thing is in the GetInfo function, you are returning with the $Filtered value before the _GetDriveLetters function runs. You'll need to swap the lines about if the _GetDriveLetters function is needed. Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) the drive letters are not important until the format process is initiated, but they need to be rechecked after the disk list is refreshed to make sure anything new plugged in is not stepped on and that the letter is still available. it is intended to run after the list is refreshed. Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
bobomb Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) What is the downside to keeping the variables global if they are allowed to be modified from anywhere in the script? (I understand you are trying to teach me good form I am just curious how it works) Edited December 5, 2021 by bobomb Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now