Leaderboard
Popular Content
Showing content with the highest reputation on 12/12/2021 in all areas
-
@mLipokNot a lot for us to go on there. What have you tried? I would suggest _WD_Alert, but I'm assuming that you've already tried that.1 point
-
.....And that's what the functions does. I have probably been talking to myself for 20 minutes 😅 so here is the function with lots of comments. I think a treeview would be better than a list but it's a simple gui and maybe overkill for the amount of drives there will most likely be. Func DiskList_Load() ; load the list control with enumerated drives ; here we get the list of fixed drive on the system. It returns an array if OK Local $as_Fixed = DriveGetDrive('FIXED') ; here we check if $as_Fixed is an array before actioning it If IsArray($as_Fixed) Then ; here we get a list of removable drive Local $as_Removable = DriveGetDrive('REMOVABLE') ; here we check if $as_Removable is an array. On my VM machine it returns an error as ; there are no removable drives so we need to check before we join the two arrays. ; This is important because we use the return from _ArrayConcatenate to update the element count ; in the as_Fixed array If IsArray($as_Removable) Then $as_Fixed[0] = _ArrayConcatenate($as_Fixed, $as_Removable, 1) - 1 GUICtrlSetData($c_DiskList, "") ; clear previous list info ; declare and initialise our variables Local _ $i_DeviceNumber = 0, _ ; set the device number to 0 as it is most theres a 0 disk $i_LastDeviceNumber = -1 ; set the value to -1 so it doesn't conflict with any disk numbers ; create a new 2D array for the device numbers. This has columns for the drive letter [0] ; and the device number [1], with enough elements for all the drives in the $as_Fixed array ; we add an extra row for the array count, I prefer this over using ubound if I am creating the arrays Local $as_DriveInfo[$as_Fixed[0] + 1][2] = [[$as_Fixed[0], 0]] ; here we loop through the drive letter array, add the letter to column 0 ; and the device number to column 1 of the array. We only need the device number ; so when we call _WinAPI_GetDriveNumber, we can add the array element we want onto the end ; and it will return that. Fuck knows how that works, but it does, and it's useful For $i = 1 To $as_Fixed[0] $as_DriveInfo[$i][0] = $as_Fixed[$i] $as_DriveInfo[$i][1] = _WinAPI_GetDriveNumber($as_Fixed[$i])[1] Next ; here we create a new array and add the numbers of the columns we want to sort the ; array on. We use UEZ's brilliant function and this requires an array ; we want to sort first by the device number, then by drive letter so we add 1 and 0 Local $ai_Columns[2] = [1, 0] ; sort the array by device number and then drive letter and sort both columns ascending ; let the function know we are using a 1 based array _ArraySort_MultiColumn($as_DriveInfo, $ai_Columns, 0, 0, 1) ; here we loop through the full 2D array containing the fixed drives and device numbers For $i = 1 To $as_DriveInfo[0][0] ; here we check if we are working on a different device number ; this is because there could be multiple volumes on a single disk ; we set the start number as -1 so it will always be different on first run ; if the device number is the same, this part is skipped If $as_DriveInfo[$i][1] <> $i_LastDeviceNumber Then ; here we are updating the list with the disk number and friendly name GUICtrlSetData($c_DiskList, 'Disk ' & $as_DriveInfo[$i][1] & ' [' & Disk_GetName($as_DriveInfo[$i][1]) & ']') ; here we set the current device number we are working on $i_LastDeviceNumber = $as_DriveInfo[$i][1] EndIf ; here we add the volume info, this is the label and the letter changed to upper case GUICtrlSetData($c_DiskList, " └ " & DriveGetLabel($as_DriveInfo[$i][0]) & " - " & "(" & StringUpper($as_DriveInfo[$i][0]) & "\ )") ; here we then continue the loop and look at the next row in the array Next EndIf EndFunc ;==>DiskList_Load1 point
-
Ok, this must be it. I have left the arraydisplay in so you can uncomment and see if it's sorted. I'll have a look at the other code if you're not happy with this. There's another function to sort on two columns as well Func DiskList_Load() ; load the list control with enumerated drives Local $as_Fixed = DriveGetDrive('FIXED') If IsArray($as_Fixed) Then Local $as_Removable = DriveGetDrive('REMOVABLE') ; join the two array to just make one loop through for the drives If IsArray($as_Removable) Then $as_Fixed[0] = _ArrayConcatenate($as_Fixed, $as_Removable, 1) - 1 GUICtrlSetData($c_DiskList, "") ; clear previous list info Local _ $i_DeviceNumber = 0, _ $i_LastDeviceNumber = -1 ; create a new 2D array for the device numbers Local $as_DriveInfo[$as_Fixed[0] + 1][2] = [[$as_Fixed[0], 0]] ; loop through the drive letter array, add the letter and the device number to the new array For $i = 1 To $as_Fixed[0] $as_DriveInfo[$i][0] = $as_Fixed[$i] $as_DriveInfo[$i][1] = _WinAPI_GetDriveNumber($as_Fixed[$i])[1] Next Local $ai_Columns[2] = [1,0] ; sort the array by device number and then drive letter _ArraySort_MultiColumn($as_DriveInfo, $ai_Columns, 0, 0, 1) ;~ _ArrayDisplay($as_DriveInfo) For $i = 1 To $as_DriveInfo[0][0] ; loop through the fixed drives ; get the drive number and device name If $as_DriveInfo[$i][1] <> $i_LastDeviceNumber Then ; add the device name to the list GUICtrlSetData($c_DiskList, 'Disk ' & $as_DriveInfo[$i][1] & ' [' & Disk_GetName($as_DriveInfo[$i][1]) & ']') $i_LastDeviceNumber = $as_DriveInfo[$i][1] EndIf ; add the partition info to the list GUICtrlSetData($c_DiskList, " └ " & DriveGetLabel($as_DriveInfo[$i][0]) & " - " & "(" & StringUpper($as_DriveInfo[$i][0]) & "\ )") Next EndIf EndFunc ;==>DiskList_Load ; #FUNCTION# ============================================================================= ; Name.............: _ArraySort_MultiColumn ; Description ...: sorts an array at given colums (multi colum sort) ; Syntax...........: _ArraySort_MultiColumn(ByRef $aSort, ByRef $aIndices) ; Parameters ...: $aSort - array to sort ; $aIndices - array with colum indices which should be sorted in specified order - zero based ; $oDir/$iDir - sort direction - if set to 1, sort descending else ascending. $oDir is for the 1st row, ; $iDir for the remaining rows ; $iStart - where to start to sort - 0 = 0 based array, 1 = 1 based array ; Author .........: UEZ ; Version ........: v0.80 build 2019-01-26 Beta ; Link............: https://www.autoitscript.com/forum/topic/197521-sort-arrays-on-multiple-columns/ ; ========================================================================================= Func _ArraySort_MultiColumn(ByRef $aSort, ByRef $aIndices, $oDir = 0, $iDir = 0, $iStart = 0) If Not IsArray($aIndices) Or Not IsArray($aSort) Then Return SetError(1, 0, 0) ;checks if $aIndices is an array If UBound($aSort, 2) = 0 Then Return SetError(4, 0, 0) ;array is 1D only If UBound($aIndices) > UBound($aSort, 2) Then Return SetError(2, 0, 0) ;check if $aIndices array is greater the $aSort array Local $1st, $2nd, $x, $j, $k, $l = 0 For $x = 0 To UBound($aIndices) - 1 ;check if array content makes sense If Not IsInt($aIndices[$x]) Then Return SetError(3, 0, 0) ;array content is not numeric Next $iStart = Int($iStart) < 0 ? 0 : Int($iStart) > 1 ? 1 : Int($iStart) If UBound($aIndices) = 1 Then Return _ArraySort($aSort, $oDir, $iStart, 0, $aIndices[0]) ;check if only one index is given _ArraySort($aSort, $oDir, $iStart, 0, $aIndices[0]) Do $1st = $aIndices[$l] $2nd = $aIndices[$l + 1] $j = 0 $k = 1 While $k < UBound($aSort) If $aSort[$j][$1st] <> $aSort[$k][$1st] Then If $k - $j > 1 Then _ArraySort($aSort, $iDir, $j, $k - 1, $2nd) $j = $k Else $j = $k EndIf EndIf $k += 1 WEnd If $k - $j > 1 Then _ArraySort($aSort, $iDir, $j, $k, $2nd) $l += 1 Until $l = UBound($aIndices) - 1 Return 1 EndFunc ;==>_ArraySort_MultiColumn1 point
-
Forgot to sort the array. Gimme a minute1 point
-
Try this Func DiskList_Load() ; load the list control with enumerated drives Local $as_Fixed = DriveGetDrive('FIXED') If IsArray($as_Fixed) Then Local $as_Removable = DriveGetDrive('REMOVABLE') ; join the two array to just make one loop through for the drives If IsArray($as_Removable) Then $as_Fixed[0] = _ArrayConcatenate($as_Fixed, $as_Removable, 1) - 1 GUICtrlSetData($c_DiskList, "") ; clear previous list info Local _ $i_DeviceNumber = 0, _ $i_LastDeviceNumber = -1 ; create a new 2D array for the device numbers Local $as_DriveInfo[$as_Fixed[0] + 1][2] = [[$as_Fixed[0], 0]] ; loop through the drive letter array, add the letter and the device number to the new array For $i = 1 To $as_Fixed[0] $as_DriveInfo[$i][0] = $as_Fixed[$i] $as_DriveInfo[$i][1] = _WinAPI_GetDriveNumber($as_Fixed[$i])[1] Next For $i = 1 To $as_DriveInfo[0][0] ; loop through the fixed drives ; get the drive number and device name If $as_DriveInfo[$i][1] <> $i_LastDeviceNumber Then ; add the device name to the list GUICtrlSetData($c_DiskList, 'Disk ' & $as_DriveInfo[$i][1] & ' [' & Disk_GetName($as_DriveInfo[$i][1]) & ']') $i_LastDeviceNumber = $as_DriveInfo[$i][1] EndIf ; add the partition info to the list GUICtrlSetData($c_DiskList, " └ " & DriveGetLabel($as_DriveInfo[$i][0]) & " - " & "(" & StringUpper($as_DriveInfo[$i][0]) & "\ )") Next EndIf EndFunc ;==>DiskList_Load1 point
-
Whats does $as_Fixed array look like if you display it (_ArrayDisplay). What order are the drives?. Wonder if the DriveGetDrive function returns them dependent on which is the system drive?1 point
-
@benners it is perfectly working, every copy that has been posted in this thread works.. I wish there was an easy way to send you a test ISO Here is where a builder is to make a PE disk.. but that is a project in itself.. https://github.com/ChrisRfr/Win10XPE The reason the drive is cleaned then "scrubbed" then cleaned again is that there is a bug in windows explorer, that if this step is not done you may (small chance) see an extra drive + letter in windows explorer that is inaccessible.. Like a phantom disk with a letter that you cannot eject and will remain if the drive is unplugged.. When this step is performed the issue is overcome. It is a very annoying bug and im happy to run clean twice to avoid it lol.. its actually not the clean part that fixes it, its the format "scrub" partition the entire disk into one partition then clean that.. it may have to do with the dual partition breakdown diskpart does during the initial clean... you generally do not partition usb sticks, and when cleaning one that is already split into partitions weird things happen lol (The phantom drive goes away if the USB is reinserted and "scrubbed") For bootable media, on Windows 7, if you have more than 1 partition on a usb, only the first partition will be seen. So for this format process we create the data partition first, it is NTFS so files larger than 4gb can be used, then shrink the drive the size we need for the boot partition (this was checked +200mb added), the boot partition is created containing the boot files as fat32 and set as active. So when the system starts it boots off the boot partition, where the boot.wim is located, and the system automaps Y: (with cdusb.y marker) to the Data partition during boot, where all the programs in the windows pe start menu live(depending on how you created your build)... Some builds have everything loaded to ram so all program are located in the boot.wim and nothing is on the data drive... But using this tool with the split partition still benefits those users because it will allow their boot wim to be loaded on the FAT32 (Mac compatible) partition, and still have the remaining space on their USB set as NTFS so they can deal with whatever file sizes they need to... The boot partition doesnt need to be accessed after the rescue pe is loaded because it contains nothing other than the files already loaded into ram.. (as I alluded earlier, boot.wim loads into ram during boot)1 point
-
I have cleaned it up a bit more. Trimmed the function that loads the list, it now loads the control from the function. Added a function for when the list is clicked that enables or disables the Burn button.. Renamed some functions to more descriptive names. I'm still not sure about the formatting and file copying though. The current setup doesn't copy any files when I run it as the drive letter changes with the diskpart calls. The drive is cleaned, then formatted and labelled "scrubber", then cleaned again, then formatted again and a primary partition is created and assigned a new drive letter. Then a primary partition is created again, assigned a drive letter and set to active. I'm struggling to undersatnd the process after the burn button is clicked. I am hard of thinking though😆 Have you successfully create the usb with this AutoIt program? I know you have said the bat file works correctly. #NoTrayIcon #RequireAdmin ;~ #Tidy_Parameters=/sf #include <Array.au3> #include <AutoItConstants.au3> #include <Constants.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <MsgBoxConstants.au3> #include <String.au3> #include <WinAPIFiles.au3> Global $c_DiskList = 0 Global $c_BurnBtn = 0 Global $bootDrive = "" Global $dataDrive = "" Opt("GUIOnEventMode", 1) ISO_CheckWasDropped() ISO_Mount() Global $s_MountedDrive = ISO_GetDriveLetter() BootWim_Check() Cleanup() DirCreate(GetCachePath()) MainMenu() Func BootWim_Check() ; check for the boot wim file If Not FileExists($s_MountedDrive & 'sources\boot.wim') Then MsgBox($MB_ICONERROR, "Notice: ", "BOOT.WIM NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.") ISO_Unmount() Exit EndIf EndFunc ;==>BootWim_Check Func BootWim_GetSize() ; get the boot wim size and add 200 megabytes for headroom on boot partition Return Round((FileGetSize($s_MountedDrive & 'sources\boot.wim') + 209715200) / 1048576) EndFunc ;==>BootWim_GetSize Func BurnPressed() Local $s_DiskNumber = StringRegExp(GUICtrlRead($c_DiskList), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0] If @error Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "An error occured retrieving the disk number") Else If MsgBox( _ BitOR($MB_TOPMOST, $MB_ICONWARNING, $MB_YESNO, $MB_DEFBUTTON2), _ 'This will FORMAT Disk ' & $s_DiskNumber, _ 'ALL DATA WILL BE ERASED FROM DISK ' & $s_DiskNumber & @CRLF & 'Are you sure you want to proceed?') = $IDYES Then GUISetState(@SW_HIDE) ProgressOn("BurnTool (XPE/SE) v2.0", "Creating Bootable Media...", "0%") Format_Prepare($s_DiskNumber) ProgressSet(5 & "%", "Formatting Disk " & $s_DiskNumber) Format_Run() ProgressSet(25 & "%", "Analyzing ISO Structure ") CleanDirList() CleanFileList() ProgressSet(26 & "%", "Copying Boot Partition ") CopyBootFiles() ;Progress in function; start at 55% CopyDataFilesF() ;Progress in function; start at 65% CopyDataFilesD() ProgressSet(100, "Finished", "ISO Applied!!") Sleep(2750) ProgressOff() Cleanup() ISO_Unmount() MsgBox($MB_ICONINFORMATION, "", " Enjoy! ") Exit EndIf EndIf EndFunc ;==>BurnPressed Func CleanDirList() ; setting GetCachePath() as the working directory so dir path needed for the files RunWait(@ComSpec & ' /c DIR /B /A:D ' & $s_MountedDrive & ' > isod.dat', GetCachePath(), @SW_HIDE) RunWait(@ComSpec & ' /c FINDSTR /V /I /C:"efi" /C:"boot" /C:"sources" isod.dat > ' & FinalDirs_GetName(), GetCachePath(), @SW_HIDE) EndFunc ;==>CleanDirList Func CleanFileList() ; setting GetCachePath() as the working directory so need dir path needed for the files RunWait(@ComSpec & ' /c DIR /B /A-D ' & $s_MountedDrive & ' > isof.dat', GetCachePath(), @SW_HIDE) RunWait(@ComSpec & ' /c FINDSTR /V /I /C:"bootmgr" /C:"menu" isof.dat > ' & FinalFiles_GetName(), GetCachePath(), @SW_HIDE) EndFunc ;==>CleanFileList Func Cleanup() If FileExists(GetCachePath()) Then DirRemove(GetCachePath(), $DIR_REMOVE) EndFunc ;==>Cleanup Func CopyBootFiles() ProgressSet(27 & "%", "Copying Boot Partition ") RunWait(@ComSpec & ' /c xcopy ' & $s_MountedDrive & 'BOOT ' & $bootDrive & ':\BOOT /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) RunWait('cmd /c xcopy ' & $s_MountedDrive & 'EFI ' & $bootDrive & ':\EFI /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) ProgressSet(40 & "%", "Copying Boot.wim, this may take a while... ") RunWait('cmd /c xcopy ' & $s_MountedDrive & 'sources ' & $bootDrive & ':\sources /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) ProgressSet(50 & "%", "Copying Boot Files ") If FileExists($s_MountedDrive & "BOOTMGR.") Then RunWait('cmd /c xcopy ' & $s_MountedDrive & 'BOOTMGR. ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($s_MountedDrive & "bootmgr.efi") Then RunWait('cmd /c xcopy ' & $s_MountedDrive & 'bootmgr.efi ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($s_MountedDrive & "bootmgr.exe") Then RunWait('cmd /c xcopy ' & $s_MountedDrive & 'bootmgr.exe ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($s_MountedDrive & "menu.lst") Then RunWait('cmd /c xcopy ' & $s_MountedDrive & 'menu.lst ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) EndFunc ;==>CopyBootFiles Func CopyDataFilesD() Local $GoFiles = (GetCachePath() & FinalDirs_GetName()), $StartProgAt, $xcopycmd, $line = "" FileOpen($GoFiles, 0) Local $aArray[1000] ReDim $aArray[_FileCountLines($GoFiles) + 1] For $i = 1 To _FileCountLines($GoFiles) $newline = FileReadLine($GoFiles, $i) $aArray[$i] = $newline Next _ArraySort($aArray) $StartProgAt = 65 For $i = 1 To UBound($aArray) - 1 If $aArray[$i] = "Programs" Then ProgressSet($StartProgAt & "%", "Copying Programs Folder, this may take a while...") RunWait('cmd /c xcopy ' & $s_MountedDrive & $aArray[$i] & ' ' & $dataDrive & ':\' & $aArray[$i] & ' /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 15) Else ProgressSet($StartProgAt & "%", "Copying " & $aArray[$i] & " Folder") RunWait('cmd /c xcopy ' & $s_MountedDrive & $aArray[$i] & ' ' & $dataDrive & ':\' & $aArray[$i] & ' /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 1) EndIf Next EndFunc ;==>CopyDataFilesD Func CopyDataFilesF() Local $GoFiles = (GetCachePath() & FinalFiles_GetName()), $StartProgAt, $xcopycmd, $line = "" FileOpen($GoFiles, 0) Local $aArray[1000] ReDim $aArray[_FileCountLines($GoFiles) + 1] For $i = 1 To _FileCountLines($GoFiles) $newline = FileReadLine($GoFiles, $i) $aArray[$i] = $newline Next _ArraySort($aArray) $StartProgAt = 55 For $i = 1 To UBound($aArray) - 1 ProgressSet($StartProgAt & "%", "Copying " & $aArray[$i]) RunWait('cmd /c xcopy ' & $s_MountedDrive & $aArray[$i] & ' ' & $dataDrive & ':\' & ' /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 1) Next EndFunc ;==>CopyDataFilesF Func Disk_GetName($i_DiskNumber) Local $s_DiskKey = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", String($i_DiskNumber)) If @error Then Return SetError(1, 0, 0) Local $s_DiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $s_DiskKey, "FriendlyName") If $s_DiskName = "" Then $s_DiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $s_DiskKey, "DeviceDesc") Return $s_DiskName EndFunc ;==>Disk_GetName Func DiskList_Load() ; load the list control with enumerated drives Local $as_Fixed = DriveGetDrive('FIXED') Local $as_Removable = DriveGetDrive('REMOVABLE') GUICtrlSetData($c_DiskList, "") ; clear previous list info ; join the two array to just make one loop throguh for the drives $as_Fixed[0] = _ArrayConcatenate($as_Fixed, $as_Removable, 1) - 1 Local _ $i_DeviceNumber = 0, _ $i_LastDeviceNumber = -1 For $i = 1 To $as_Fixed[0] ; loop through the fixed drives ; get info on the fixed drive $aDriveInfo = _WinAPI_GetDriveNumber($as_Fixed[$i]) $i_DeviceNumber = $aDriveInfo[1] ; get the drive number and device name If $i_DeviceNumber <> $i_LastDeviceNumber Then ; add the device name to the list GUICtrlSetData($c_DiskList, 'Disk ' & $i_DeviceNumber & ' [' & Disk_GetName($i_DeviceNumber) & ']') $i_LastDeviceNumber = $i_DeviceNumber EndIf ; add the partition info to the list GUICtrlSetData($c_DiskList, " └ " & DriveGetLabel($as_Fixed[$i]) & " - " & "(" & StringUpper($as_Fixed[$i]) & "\ )") Next EndFunc ;==>DiskList_Load Func DiskList_Selected() ; action when a list item is selected Local $i_State = $GUI_ENABLE If GUICtrlRead($c_DiskList) = '' Or StringInStr(GUICtrlRead($c_DiskList), " └ ") Then $i_State = $GUI_DISABLE GUICtrlSetState($c_BurnBtn, $i_State) EndFunc ;==>DiskList_Selected Func Diskpart_CreateScriptFile($s_File, $s_Data) Local $CacheFile = FileOpen(GetCachePath() & $s_File, 2) FileWrite($CacheFile, $s_Data) FileClose($CacheFile) EndFunc ;==>Diskpart_CreateScriptFile Func FinalDirs_GetName() ; get the name for the final dirs to copy Return 'isodirs.dat' EndFunc ;==>FinalDirs_GetName Func FinalFiles_GetName() ; get the names of the final files to copy Return 'isofiles.dat' EndFunc ;==>FinalFiles_GetName Func Format_Prepare($s_Drive) GetDriveLetters() Diskpart_CreateScriptFile('clean.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'clean' & @CRLF & 'Exit') Diskpart_CreateScriptFile('attrib.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit') Diskpart_CreateScriptFile('scrubber.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=scrubber' & @CRLF & 'Exit') Diskpart_CreateScriptFile('convert.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'convert mbr' & @CRLF & 'Exit') Diskpart_CreateScriptFile('initdata.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'shrink minimum=' & BootWim_GetSize() & @CRLF & 'format quick fs=ntfs label="WinPE Data"' & @CRLF & 'assign letter=' & $dataDrive & @CRLF & 'Exit') Diskpart_CreateScriptFile('initboot.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=fat32 label="BOOTFILES"' & @CRLF & 'assign letter=' & $bootDrive & @CRLF & 'Active' & @CRLF & 'Exit') EndFunc ;==>Format_Prepare Func Format_Run() Local $aArray[7][3] = [ _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'clean.dat' & '"'], _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'scrub.dat' & '"'], _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'clean.dat' & '"'], _ ["Resetting Disk Attributes", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'attrib.dat' & '"'], _ ["Converting Layout to MBR", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'convert.dat' & '"'], _ ["Creating Data Partition", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'initdata.dat' & '"'], _ ["Creating Boot Partition", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'initboot.dat' & '"'] _ ] For $i = 0 To UBound($aArray) - 1 ProgressSet($i * 2 & "%", $aArray[$i][0]) ;~ ConsoleWrite('cmd: ' & $aArray[$i][1] & @CRLF) RunWait($aArray[$i][1], @WorkingDir, @SW_HIDE) Sleep(750) Next EndFunc ;==>Format_Run Func GetCachePath() ; get the path to the cache folder Local Static $s_CachePath = IniRead(@WorkingDir & '\USBTool.ini', "Settings", "CachePath", @WorkingDir & '\cache') & '\' Return $s_CachePath EndFunc ;==>GetCachePath Func GetDriveLetters() Local $allDriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ", $AvailDriveLetters Local $aArray = DriveGetDrive($DT_ALL) If @error Then ; An error occurred when retrieving the drives. MsgBox($MB_SYSTEMMODAL, "", "An Error Occurred! Unable to retrieve " & @CRLF & "available drive letters! Exiting Program...") Cleanup() ISO_Unmount() Exit Else For $i = 1 To $aArray[0] $driveLetter = StringLeft(StringUpper($aArray[$i]), 1) $allDriveLetters = StringReplace($allDriveLetters, $driveLetter, "") Next EndIf $AvailDriveLetters = StringSplit($allDriveLetters, "") $bootDrive = $AvailDriveLetters[1] ; Get first available letter $dataDrive = $AvailDriveLetters[2] ; Get second available letter ;~ ConsoleWrite('boot drive: ' & $bootDrive & @CRLF) ;~ ConsoleWrite('data drive: ' & $dataDrive & @CRLF) EndFunc ;==>GetDriveLetters Func ISO_CheckWasDropped() ; check that an iso was dropped on to the exe If $CmdLine[0] = 0 Then ; no file was dropped or passed via the command line MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "This program cannot be run directly!" & @CRLF & "Please drag an ISO onto the program to begin...") Exit EndIf EndFunc ;==>ISO_CheckWasDropped Func ISO_GetDriveLetter() ; get the drive letter of the mounted iso ;~ Local $s_MarkerFile = 'CdUsb.Y' Local $s_MarkerFile = 'BOOTMGR' Local $s_IsoDrive = '' Local $as_CDROM = DriveGetDrive($DT_CDROM) For $i = 1 To $as_CDROM[0] If FileExists($as_CDROM[$i] & '\' & $s_MarkerFile) Then If Not _WinAPI_IsWritable($as_CDROM[$i]) Then $s_IsoDrive = $as_CDROM[$i] & '\' EndIf Next If $s_IsoDrive = "" Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ $s_MarkerFile & " NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.") Exit EndIf Return $s_IsoDrive EndFunc ;==>ISO_GetDriveLetter Func ISO_Mount() ; mount the droppped iso RunWait('cmd /c powershell.exe ' & '"Mount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>ISO_Mount Func ISO_Unmount() ; unmount the dropped iso RunWait('cmd /c powershell.exe ' & '"Dismount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>ISO_Unmount Func MainMenu() ; draw the gui GUICreate('BurnTool (XPE/SE) v2.0', 300, 287) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUISetIcon(@WorkingDir & '\USBTool.ico', 1) GUISetBkColor(0x797979) GUICtrlCreateLabel('Select a disk to use...', 20, 10, 280) $c_DiskList = GUICtrlCreateList('', 20, 30, 260, 150, BitXOR($GUI_SS_DEFAULT_LIST, $LBS_SORT)) DiskList_Load() GUICtrlSetOnEvent(-1, "DiskList_Selected") GUICtrlCreateButton('Refresh List', 110, 187, 80, 25) GUICtrlSetOnEvent(-1, "RefreshPressed") GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('________________________________________', 30, 210, 280, 30) $c_BurnBtn = GUICtrlCreateButton('Burn', 90, 232, 120, 40) GUICtrlSetOnEvent(-1, "BurnPressed") GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() ; Just idle around While 1 Sleep(10) WEnd EndFunc ;==>MainMenu Func RefreshPressed() DiskList_Load() DiskList_Selected() EndFunc ;==>RefreshPressed Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ; Code below for actions on Close Cleanup() ISO_Unmount() Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE ; Code below for actions on Minimize Case @GUI_CtrlId = $GUI_EVENT_RESTORE ; Code below for actions on Restore EndSelect EndFunc ;==>SpecialEvents1 point
-
Keep it simple: string -> *_Escape, binary -> *_Encode Numeric values (at least true ones) don't pose any problem, unless you beg for problems: Local $v = "123';drop table X;--haha, fool you" If $v <> 0 Then ConsoleWrite("select * from x where id like '" & $v) ConsoleWrite(@CRLF) EndIf RULE: always sanitize user input. EDIT: note that the example also works without the single quotes game. Local $v = "123;drop table X;--haha, fool you" If $v > 100 Then ConsoleWrite("select * from x where id like " & $v) ConsoleWrite(@CRLF) EndIf1 point
-
I can mount the iso and remove the check for the marker file or comment out function, as I have been doing but if I am altering your code, I like to test it as much as possible before I post it and run it as it was intended. I also have to remember to remove the comments on the code. Some folks who know what they are talking about can write code that is untested and it works first time, I have been helped this way before, but I tend to overthink things 😁. With the mount and unmount functions I couldn't test them. I would make a few more changes to the code but it feels like I am taking over, I don't want to impose the way I like to do things on you, as its better if you develop your own style as it's part of the process. If you don't specify styles then AutoIt will use whatever has been set as the default style. As you have found, the help file has loads of info on the different styles and each has it's own constant value. You could just add them up or subtract one style from another like this. $GUI_SS_DEFAULT_LIST - $LBS_SORT The correct\better? way is to perform a bitwise operation on the values. Basically if I want to add numbers or styles I use BitOR, and BitXOR to subtract them. The list isn't sorting them now. In the GetDiskList function, there is a line that sorts the array. If it's not needed, either comment it out or delete it.The partitions will be displayed correctly. _ArraySort($aDrives, 0, 0, 0, 1) As you mentioned, because of the nature of the program, it would be quite easy to hose a partition and lose whatever was on it. When it is working correctly, you will want to start adding error checking for values returned from functions or actions performed by the functions. I only have 1 drive split into two partitions. I have plugged a in a usb drive to test this but if I lose focus and run the program on the main drive I will be up shit creek1 point
-
I tidied some more functions up. I have tested them as much as I can so you'll have to check them on your end. There is an issue in the other posts in format where one file is called scrub.dat when it should be scrubber.dat. I'm on Windows 7 so no Mount-Image cmdlet for me. Editied post above as well. Func CleanDirList() ; setting GetCachePath() as the working directory so need dir path needed for the files $finaldirs = 'isodirs.dat' RunWait(@ComSpec & ' /c DIR /B /A:D ' & $MountedDrive & ':\ > isod.dat', GetCachePath(), @SW_HIDE) RunWait(@ComSpec & ' /c FINDSTR /V /I /C:"efi" /C:"boot" /C:"sources" isod.dat > ' & $finaldirs, GetCachePath(), @SW_HIDE) EndFunc ;==>CleanDirList Func CleanFileList() ; setting GetCachePath() as the working directory so need dir path needed for the files $finalfiles = 'isofiles.dat' Local $MountedDrive = 'E' RunWait(@ComSpec & ' /c DIR /B /A-D ' & $MountedDrive & ':\ > isof.dat', GetCachePath(), @SW_HIDE) RunWait(@ComSpec & ' /c FINDSTR /V /I /C:"bootmgr" /C:"menu" isof.dat > ' & $finalfiles, GetCachePath(), @SW_HIDE) EndFunc ;==>CleanFileList Func Format() ; using notepad to test the files open. Will need you to check on your end for the diskpart Local $as_Process[7][2] = [ _ [6, 0], _ ["Cleaning Drive", 'clean.dat'], _ ["Formatting Drive", 'scrubber.dat'], _ ["Resetting Disk Attributes", 'attrib.dat'], _ ["Converting Layout to MBR", 'convert.dat'], _ ["Creating Data Partition", 'initdata.dat'], _ ["Creating Boot Partition", 'initboot.dat'] _ ] For $i = 1 To $as_Process[0][0] ConsoleWrite('Process: ' & $as_Process[$i][0] & @CRLF) RunWait('notepad.exe ' & $as_Process[$i][1], GetCachePath()) ;~ RunWait(@ComSpec & ' /c diskpart /s ' & $as_Process[$i][1], GetCachePath(), @SW_HIDE) Next EndFunc ;==>Format Func ProperUse() ; needs $IsoFile replacing with $CmdLine[1] If $CmdLine[0] = 0 Then ; no file was dropped or passed via the command line MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "This program cannot be run directly!" & @CRLF & "Please drag an ISO onto the program to begin...") Exit EndIf EndFunc ;==>ProperUse1 point
-
Sorted. The issue was with the list styles. By default it is sorted. Just needed the styles changing #NoTrayIcon #RequireAdmin #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <MsgBoxConstants.au3> #include <Constants.au3> #include <File.au3> #include <Array.au3> #include <String.au3> Global $DiskList, $Selection, $IsoFile, $MountedDrive = "" Global $finalfiles, $finaldirs, $wimSize, $bootDrive, $dataDrive ProperUse() MountIso() GetISODriveLetter() BootWim_Check() Cleanup() DirCreate(GetCachePath()) Opt("GUIOnEventMode", 1) MainMenu() Cleanup() Exit Func MainMenu() GUICreate('Burn Tool (XPE/SE) v2.0', 300, 298) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUISetIcon(@WorkingDir & '\USBTool.ico', 1) GUISetBkColor(0x797979) GUICtrlCreateLabel('1: Select a disk to use...', 20, 10, 280) $DiskList = GUICtrlCreateList('', 20, 30, 260, 150, BitXOR($GUI_SS_DEFAULT_LIST, $LBS_SORT)) GUICtrlSetData(-1, GetDiskList()) $Refresh = GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetOnEvent(-1, "RefreshPressed") GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('________________________________________', 30, 210, 280, 30) $Burn = GUICtrlCreateButton('Burn', 90, 232, 120, 40) GUICtrlSetOnEvent(-1, "BurnPressed") GUICtrlCreateLabel('( * ) Disk is Currently GPT', 160, 278, 130, 30) GUISetState() ; Just idle around While 1 Sleep(10) WEnd EndFunc ;==>MainMenu Func RefreshPressed() GUICtrlSetData($DiskList, "") GUICtrlSetData($DiskList, GetDiskList()) EndFunc ;==>RefreshPressed Func BurnPressed() If GUICtrlRead($DiskList) = '' Or StringInStr(GUICtrlRead($DiskList), 'partition') Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "Please select a disk number") Else Local $s_DiskNumber = StringRegExp(GUICtrlRead($DiskList), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0] If @error Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "An error occured retrieving the disk number") Else If MsgBox( _ BitOR($MB_TOPMOST, $MB_ICONWARNING, $MB_YESNO, $MB_DEFBUTTON2), _ 'This will FORMAT Disk ' & $s_DiskNumber, _ 'ALL DATA WILL BE ERASED FROM DISK ' & $s_DiskNumber & @CRLF & 'Are you sure you want to proceed?') = $IDYES Then GUISetState(@SW_HIDE) ProgressOn("Applying ISO...", "Creating Bootable Media... ", "0%") PrepFormat($s_DiskNumber) ProgressSet(5 & "%", "Formatting Disk " & $s_DiskNumber) Format() ProgressSet(25 & "%", "Analyzing ISO Structure ") CleanDirList() CleanFileList() ProgressSet(26 & "%", "Copying Boot Partition ") CopyBootFiles() ;Progress in function; start at 55% CopyDataFilesF() ;Progress in function; start at 65% CopyDataFilesD() ProgressSet(100, "Finished", "ISO Applied!!") Sleep(2750) ProgressOff() Cleanup() UnmountIso() MsgBox($MB_ICONINFORMATION, "", " Enjoy! ") Exit EndIf EndIf EndIf EndFunc ;==>BurnPressed Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ; Code below for actions on Close Cleanup() UnmountIso() Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE ; Code below for actions on Minimize Case @GUI_CtrlId = $GUI_EVENT_RESTORE ; Code below for actions on Restore EndSelect EndFunc ;==>SpecialEvents Func ProperUse() If Not ($CmdLine[0]) = 0 Then ;Something was dropped on the EXE file or CLI was used with a flag(s) $IsoFile = ($CmdLine[1]) ;Sets $IsoFile var to the full path of whatever was dropped onto the EXE file or the 1st CLI flag that was used Else MsgBox($MB_ICONERROR, "Notice: ", "This program cannot be run directly!" & @CRLF & "Please drag an ISO onto" & @CRLF & "the program to begin...") Exit EndIf EndFunc ;==>ProperUse Func BootWim_Check() ; check for the boot wim file If Not FileExists($MountedDrive & ':\sources\boot.wim') Then MsgBox($MB_ICONERROR, "Notice: ", "BOOT.WIM NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.") UnmountIso() Exit EndIf EndFunc ;==>BootWim_Check Func BootWim_GetSize() ; get the boot wim size and add 200 megabytes for headroom on boot partition Return Round((FileGetSize($MountedDrive & ':\sources\boot.wim') + 209715200) / 1048576) EndFunc ;==>BootWim_GetSize Func MountIso() RunWait('cmd /c powershell.exe ' & '"Mount-DiskImage "' & '"' & $IsoFile & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>MountIso Func UnmountIso() RunWait('cmd /c powershell.exe ' & '"Dismount-DiskImage "' & '"' & $IsoFile & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>UnmountIso Func Cleanup() If FileExists(GetCachePath()) Then DirRemove(GetCachePath(), $DIR_REMOVE) EndIf EndFunc ;==>Cleanup Func GetISODriveLetter() Local $findiso = StringSplit("CDEFGHIJKLMNOPQRSTUVWXYZ", "", 1) For $i = 1 To $findiso[0] Step +1 $isoExists = FileExists($findiso[$i] & ":\CdUsb.Y") If $isoExists Then If PathIsWritable($findiso[$i] & ":\") = False Then $MountedDrive = ($findiso[$i]) EndIf EndIf Next If $MountedDrive = "" Then MsgBox($MB_ICONERROR, "Notice: ", "CdUsb.Y NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.") Exit EndIf EndFunc ;==>GetISODriveLetter Func PathIsWritable($sFile) Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateFileW', _ 'wstr', $sFile, _ 'dword', 2, _ 'dword', 7, _ 'struct*', 0, _ 'dword', 3, _ 'dword', 0x02000000, _ 'handle', 0) If @error Or $aRet[0] = Ptr(-1) Or $aRet[0] = 0 Then Return False DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $aRet[0]) Return True EndFunc ;==>PathIsWritable Func GetDiskList() Local $aDriveInfo, $iLastDevNumber = -1 Local $aFixed = DriveGetDrive('FIXED'), $aRemovable = DriveGetDrive('REMOVABLE') Local $aDrives[(IsArray($aFixed) ? $aFixed[0] : 0) + (IsArray($aRemovable) ? $aRemovable[0] : 0)][3] Local $iDrive = 0 For $i = 1 To UBound($aFixed) - 1 $aDrives[$iDrive][0] = $aFixed[$i] $aDriveInfo = _WinAPI_GetDriveNumber($aFixed[$i]) If Not @error Then $aDrives[$iDrive][1] = $aDriveInfo[1] $aDrives[$iDrive][2] = $aDriveInfo[2] EndIf $iDrive += 1 Next For $i = 1 To UBound($aRemovable) - 1 $aDrives[$iDrive][0] = $aRemovable[$i] $aDriveInfo = _WinAPI_GetDriveNumber($aRemovable[$i]) If Not @error Then $aDrives[$iDrive][1] = $aDriveInfo[1] $aDrives[$iDrive][2] = $aDriveInfo[2] EndIf $iDrive += 1 Next _ArraySort($aDrives, 0, 0, 0, 1) Local $sDrivesInfo, $s_Drives For $i = 0 To UBound($aDrives) - 1 If IsNumber($aDrives[$i][1]) Then If $aDrives[$i][1] <> $iLastDevNumber Then $sDrivesInfo &= "Disk " & $aDrives[$i][1] & " [" & _GetDiskNameByNumber($aDrives[$i][1]) & "]" & "|" & @CRLF $iLastDevNumber = $aDrives[$i][1] EndIf $sDrivesInfo &= " - Partition #" & $aDrives[$i][2] & " " & DriveGetLabel($aDrives[$i][0]) & " - " & StringUpper($aDrives[$i][0]) & "|" & @CRLF EndIf Next Return $sDrivesInfo EndFunc ;==>GetDiskList Func _GetDiskNameByNumber($iDiskNumber) Local $iCount = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", "Count") Local $sDiskKey = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", String($iDiskNumber)) If @error Then Return SetError(1, 0, 0) Local $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "FriendlyName") If $sDiskName = "" Then $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "DeviceDesc") Return $sDiskName EndFunc ;==>_GetDiskNameByNumber Func GetCachePath() Local Static $s_CachePath = IniRead(@WorkingDir & '\USBTool.ini', "Settings", "CachePath", @WorkingDir & '\cache') & '\' Return $s_CachePath EndFunc ;==>GetCachePath Func PrepFormat($Drive) GetDriveLetters() createDiskPartScriptFile(GetCachePath() & 'clean.dat', 'Sel Dis ' & $Drive & @CRLF & 'clean' & @CRLF & 'Exit') createDiskPartScriptFile(GetCachePath() & 'attrib.dat', 'Sel Dis ' & $Drive & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit') createDiskPartScriptFile(GetCachePath() & 'scrubber.dat', 'Sel Dis ' & $Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=scrubber' & @CRLF & 'Exit') createDiskPartScriptFile(GetCachePath() & 'convert.dat', 'Sel Dis ' & $Drive & @CRLF & 'convert mbr' & @CRLF & 'Exit') createDiskPartScriptFile(GetCachePath() & 'initdata.dat', 'Sel Dis ' & $Drive & @CRLF & 'cre par pri' & @CRLF & 'shrink minimum=' & BootWim_GetSize() & @CRLF & 'format quick fs=ntfs label="WinPE Data"' & @CRLF & 'assign letter=' & $dataDrive & @CRLF & 'Exit') createDiskPartScriptFile(GetCachePath() & 'initboot.dat', 'Sel Dis ' & $Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=fat32 label="BOOTFILES"' & @CRLF & 'assign letter=' & $bootDrive & @CRLF & 'Active' & @CRLF & 'Exit') EndFunc ;==>PrepFormat Func CopyBootFiles() RunWait('cmd /c xcopy ' & $MountedDrive & ':\BOOT ' & $bootDrive & ':\BOOT /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) ProgressSet(27 & "%", "Copying Boot Partition ") RunWait('cmd /c xcopy ' & $MountedDrive & ':\EFI ' & $bootDrive & ':\EFI /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) ProgressSet(40 & "%", "Copying Boot.wim, this may take a while... ") RunWait('cmd /c xcopy ' & $MountedDrive & ':\sources ' & $bootDrive & ':\sources /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE) ProgressSet(50 & "%", "Copying Boot Files ") If FileExists($MountedDrive & ":\BOOTMGR.") Then RunWait('cmd /c xcopy ' & $MountedDrive & ':\BOOTMGR. ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($MountedDrive & ":\bootmgr.efi") Then RunWait('cmd /c xcopy ' & $MountedDrive & ':\bootmgr.efi ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($MountedDrive & ":\bootmgr.exe") Then RunWait('cmd /c xcopy ' & $MountedDrive & ':\bootmgr.exe ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) If FileExists($MountedDrive & ":\menu.lst") Then RunWait('cmd /c xcopy ' & $MountedDrive & ':\menu.lst ' & $bootDrive & ':\ /h /r /v /y', @WorkingDir, @SW_HIDE) EndFunc ;==>CopyBootFiles Func CopyDataFilesF() Local $GoFiles = (GetCachePath() & $finalfiles), $StartProgAt, $xcopycmd, $line = "" FileOpen($GoFiles, 0) Local $aArray[1000] ReDim $aArray[_FileCountLines($GoFiles) + 1] For $i = 1 To _FileCountLines($GoFiles) $newline = FileReadLine($GoFiles, $i) $aArray[$i] = $newline Next _ArraySort($aArray) $StartProgAt = 55 For $i = 1 To UBound($aArray) - 1 ProgressSet($StartProgAt & "%", "Copying " & $aArray[$i]) RunWait('cmd /c xcopy ' & $MountedDrive & ':\' & $aArray[$i] & ' ' & $dataDrive & ':\' & ' /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 1) Next EndFunc ;==>CopyDataFilesF Func CopyDataFilesD() Local $GoFiles = (GetCachePath() & $finaldirs), $StartProgAt, $xcopycmd, $line = "" FileOpen($GoFiles, 0) Local $aArray[1000] ReDim $aArray[_FileCountLines($GoFiles) + 1] For $i = 1 To _FileCountLines($GoFiles) $newline = FileReadLine($GoFiles, $i) $aArray[$i] = $newline Next _ArraySort($aArray) $StartProgAt = 65 For $i = 1 To UBound($aArray) - 1 If $aArray[$i] = "Programs" Then ProgressSet($StartProgAt & "%", "Copying Programs Folder, this may take a while...") RunWait('cmd /c xcopy ' & $MountedDrive & ':\' & $aArray[$i] & ' ' & $dataDrive & ':\' & $aArray[$i] & ' /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 15) Else ProgressSet($StartProgAt & "%", "Copying " & $aArray[$i] & " Folder") RunWait('cmd /c xcopy ' & $MountedDrive & ':\' & $aArray[$i] & ' ' & $dataDrive & ':\' & $aArray[$i] & ' /i /s /e /h /r /v /y', @WorkingDir, @SW_HIDE, 2) $StartProgAt = ($StartProgAt + 1) EndIf Next EndFunc ;==>CopyDataFilesD Func createDiskPartScriptFile($fileName, $message) $CacheFile = '' $CacheFile = FileOpen($fileName, 2) FileWrite($CacheFile, $message) FileClose($CacheFile) EndFunc ;==>createDiskPartScriptFile Func GetDriveLetters() Local $allDriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ", $AvailDriveLetters Local $aArray = DriveGetDrive($DT_ALL) If @error Then ; An error occurred when retrieving the drives. MsgBox($MB_SYSTEMMODAL, "", "An Error Occurred! Unable to retrieve " & @CRLF & "available drive letters! Exiting Program...") Cleanup() UnmountIso() Exit Else For $i = 1 To $aArray[0] $driveLetter = StringLeft(StringUpper($aArray[$i]), 1) $allDriveLetters = StringReplace($allDriveLetters, $driveLetter, "") Next EndIf $AvailDriveLetters = StringSplit($allDriveLetters, "") $bootDrive = $AvailDriveLetters[1] ;Get first available letter $dataDrive = $AvailDriveLetters[2] ;Get second available letter EndFunc ;==>GetDriveLetters Func CleanDirList() Local $rawlist = 'isod.dat' $finaldirs = 'isodirs.dat' RunWait('cmd /c DIR /B /A:D ' & $MountedDrive & ':\>' & '"' & GetCachePath() & $rawlist & '"', @WorkingDir, @SW_HIDE) RunWait('cmd /c FINDSTR /v /i /c:' & '"' & 'efi' & '"' & ' /c:' & '"' & 'boot' & '"' & ' /c:' & '"' & 'sources' & '"' & ' "' & GetCachePath() & $rawlist & '"' & '>>' & '"' & GetCachePath() & $finaldirs & '"', @WorkingDir, @SW_HIDE) EndFunc ;==>CleanDirList Func CleanFileList() Local $rawlist = 'isof.dat' $finalfiles = 'isofiles.dat' RunWait('cmd /c DIR /B /A-D ' & $MountedDrive & ':\>' & '"' & GetCachePath() & $rawlist & '"', @WorkingDir, @SW_HIDE) RunWait('cmd /c FINDSTR /v /i /c:' & '"' & 'bootmgr' & '"' & ' /c:' & '"' & 'menu' & '"' & ' "' & GetCachePath() & $rawlist & '"' & '>>' & '"' & GetCachePath() & $finalfiles & '"', @WorkingDir, @SW_HIDE) EndFunc ;==>CleanFileList Func Format() Local $aArray[7][3] = [ _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'clean.dat' & '"'], _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'scrub.dat' & '"'], _ ["Cleaning Drive", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'clean.dat' & '"'], _ ["Resetting Disk Attributes", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'attrib.dat' & '"'], _ ["Converting Layout to MBR", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'convert.dat' & '"'], _ ["Creating Data Partition", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'initdata.dat' & '"'], _ ["Creating Boot Partition", 'cmd /c diskpart /s ' & '"' & GetCachePath() & 'initboot.dat' & '"'] _ ] For $i = 0 To UBound($aArray) - 1 ProgressSet($i * 2 & "%", $aArray[$i][0]) ;MsgBox($MB_ICONINFORMATION, "Troubleshooting.. ", $aArray[$i][1]) ;Troubleshoot Array Data RunWait($aArray[$i][1], @WorkingDir, @SW_HIDE) Sleep(750) Next EndFunc ;==>Format1 point
-
1.) Cleanfilelist and CleanDirlist remove all traces of boot files/folders from the data partition file list. The Boot files are always the same but the data files are an unknown factor depending on how you create your media. Originally this was a simple cmd script with text interface, I could hardcode the paths for the necessary bootfiles but not the other data...originally thats how I was doing it so I just have to break from that method is all... 2.) This faster than rufus by a noticeable amount on USB 2.0 drives(when lots of small files are involved) but no real difference on faster 3.0 drives, maybe a few seconds. Its simpler, and it can be used on fixed HDD's... Rufus cannot... The original cmd script I made was before rufus allowed for UEFI + Legacy support option you used to have to choose one or the other with Rufus...I think sometime between 3.11 and 3.13. Cmd script works perfect still I just am doing this to replace the the below CMD script and retire it. And ALSO MAINLY to learn.... Just as a reference the original CMD below (Dont want to post cmd scripts but we have been going over it so much I wanted to show u where this whole thing came from) @ECHO OFF CLS SETLOCAL EnableExtensions EnableDelayedExpansion TITLE Bob.Omb's USB Creation Tool :PROPERUSE IF [%1]==[] GOTO IMPROPERUSE POWERSHELL.EXE "Mount-DiskImage ""%1""" >nul for /f "tokens=3 delims=\:" %%d in ('reg query hklm\system\mounteddevices ^| findstr /c:"5C003F00" ^| findstr /v "{.*}"') do ( IF EXIST %%d:\CdUsb.Y SET SOURCE=%%d ) IF NOT EXIST %SOURCE%:\CdUsb.Y GOTO NOTCOMPAT2 SET SIZE=0 CALL :FILESIZE "%SOURCE%:\sources\boot.wim" SET /A SIZE=(%size%+209715000)/1048576 GOTO CHECKSIZE :FILESIZE SET SIZE=%~z1 EXIT /b 0 :CHECKSIZE IF [%SIZE%]==[] GOTO NOTCOMPAT1 :BOOTDRV SET "s=" FOR %%s IN (I J K L M N O P Q) DO ( IF NOT EXIST %%s: SET "BOOTDRV=%%s" && GOTO PROGDRV ) :PROGDRV SET "t=" FOR %%t IN (R S T U V W X Y Z) DO ( IF NOT EXIST %%t: SET "PROGDRV=%%t" && GOTO INIT1 ) :INIT1 CLS ECHO Bob.Omb's USB Creation Tool ECHO -------------------------------------------- IF EXIST "%~dp0TempUSB" DEL /S /Q "%~dp0TempUSB\*.*" >nul MD "%~dp0TempUSB" >nul ECHO list disk >"%~dp0TempUSB\list.txt" diskpart /s "%~dp0TempUSB\list.txt" ECHO. DEL "%~dp0TempUSB\list.txt" SET /p disk="Select the disk number for your USB Drive (e.g. 2): " IF [%DISK%]==[] GOTO CHOOSEABORT ECHO. IF %DISK%==0 ECHO THIS IS USUALLY YOUR SYSTEM DRIVE! ARE YOU SURE? & ECHO. ECHO --WARNING-- This will FORMAT the selected disk and ERASE ALL DATA ECHO. ECHO MAKE SURE YOU ARE SELECTING THE CORRECT DISK!! ECHO. ECHO You selected disk ---^> %disk% ECHO. CHOICE /C YN /M "Is this correct " IF %ERRORLEVEL%==1 GOTO INIT2 IF %ERRORLEVEL%==2 GOTO INIT1 :ABORT CLS ECHO -Cleaning Up- CD /D %~dp0 IF EXIST "%~dp0TempUSB\*.*" DEL /S /Q "%~dp0TempUSB\*.*" >nul IF EXIST "%~dp0TempUSB" RD "%~dp0TempUSB" >nul POWERSHELL.EXE "Dismount-DiskImage ""%1""" >nul ECHO Process Aborted, No changes have been made... ECHO. PAUSE EXIT :INIT2 ECHO select disk %disk% >"%~dp0TempUSB\init.txt" ECHO attribute disk clear readonly >>"%~dp0TempUSB\init.txt" ECHO clean >>"%~dp0TempUSB\init.txt" ECHO exit >>"%~dp0TempUSB\init.txt" ECHO select disk %disk% >"%~dp0TempUSB\initdata.txt" ECHO clean >>"%~dp0TempUSB\initdata.txt" ECHO convert mbr >>"%~dp0TempUSB\initdata.txt" ECHO create partition primary >>"%~dp0TempUSB\initdata.txt" ECHO shrink minimum=%SIZE% >>"%~dp0TempUSB\initdata.txt" ECHO format quick fs=ntfs label="WinPE Data" >>"%~dp0TempUSB\initdata.txt" ECHO assign letter=%PROGDRV% >>"%~dp0TempUSB\initdata.txt" ECHO exit >>"%~dp0TempUSB\initdata.txt" ECHO select disk %disk% >"%~dp0TempUSB\initboot.txt" ECHO create partition primary>>"%~dp0TempUSB\initboot.txt" ECHO format quick fs=fat32 label="BOOTFILES" >>"%~dp0TempUSB\initboot.txt" ECHO assign letter=%BOOTDRV% >>"%~dp0TempUSB\initboot.txt" ECHO active >>"%~dp0TempUSB\initboot.txt" ECHO exit >>"%~dp0TempUSB\initboot.txt" :RUNMBR CLS ECHO Bob.Omb's USB Creation Tool ECHO -------------------------------------------- ECHO. CD /D "%~dp0" ECHO Preparing Disk %disk%... ECHO. diskpart /s "%~dp0TempUSB\init.txt" >nul ECHO. ECHO Formatting Data Section of Disk %disk%... ECHO. diskpart /s "%~dp0TempUSB\initdata.txt" >nul ECHO. ECHO Formatting Boot Section of Disk %disk%... diskpart /s "%~dp0TempUSB\initboot.txt" >nul ECHO. ECHO -Preparing FileCopy- :COPYBOOTFILES CD /D %SOURCE%: IF EXIST "%~dp0TempUSB\isod.txt" DEL "%~dp0TempUSB\isod.txt" IF EXIST "%~dp0TempUSB\isodirs.txt" DEL "%~dp0TempUSB\isodirs.txt" DIR /B /A:D>"%~dp0TempUSB\isod.txt" FINDSTR /v /i /c:"efi" /c:"boot" /c:"sources" "%~dp0TempUSB\isod.txt">>"%~dp0TempUSB\isodirs.txt" DEL "%~dp0TempUSB\isod.txt" >nul IF EXIST "%~dp0TempUSB\isof.txt" DEL "%~dp0TempUSB\isof.txt" IF EXIST "%~dp0TempUSB\isofiles.txt" DEL "%~dp0TempUSB\isofiles.txt" DIR /B /A-D>"%~dp0TempUSB\isof.txt" FINDSTR /v /i /c:"bootmgr" /c:"menu" "%~dp0TempUSB\isof.txt">>"%~dp0TempUSB\isofiles.txt" DEL "%~dp0TempUSB\isof.txt" >nul ECHO. ECHO -Copying Boot Files- XCOPY %SOURCE%:\BOOT %BOOTDRV%:\BOOT /i /s /e /r /v /h /y XCOPY %SOURCE%:\EFI %BOOTDRV%:\EFI /i /s /e /r /v /h /y ECHO THE SOURCES FOLDER MAY TAKE A WHILE - PLEASE BE PATIENT ECHO USB 3.0 = Approx 1-3 minutes ECHO USB 2.0 = Approx 5-15 minutes XCOPY %SOURCE%:\sources %BOOTDRV%:\sources /i /s /e /r /v /h /y IF EXIST %SOURCE%:\BOOTMGR. XCOPY %SOURCE%:\BOOTMGR. %BOOTDRV%:\ /r /v /h /y IF EXIST %SOURCE%:\bootmgr.efi XCOPY %SOURCE%:\bootmgr.efi %BOOTDRV%:\ /r /v /h /y IF EXIST %SOURCE%:\bootmgr.exe XCOPY %SOURCE%:\bootmgr.exe %BOOTDRV%:\ /r /v /h /y IF EXIST %SOURCE%:\menu.lst XCOPY %SOURCE%:\menu.lst %BOOTDRV%:\ /r /v /h /y ECHO. ECHO -Copying Program Files- CD /D %~dp0 pushd "%~dp0TempUSB" SET "a=" for /f "tokens=* delims=" %%a in ('TYPE ISODIRS.TXT') do xcopy /isehrvy "%SOURCE%:\%%a" "%PROGDRV%:\%%a" popd DEL /S /Q "%~dp0TempUSB\isodirs.txt" >nul pushd "%~dp0TempUSB" SET "a=" for /f "tokens=* delims=" %%a in ('TYPE ISOFILES.TXT') do xcopy /hrvy "%SOURCE%:\%%a" "%PROGDRV%:\" popd DEL /S /Q "%~dp0TempUSB\isofiles.txt" >nul ECHO. ECHO -Cleaning Up- ENDLOCAL CD /D %~dp0 IF EXIST "%~dp0TempUSB\*.*" DEL /S /Q "%~dp0TempUSB\*.*" >nul IF EXIST "%~dp0TempUSB" RD "%~dp0TempUSB" >nul POWERSHELL.EXE "Dismount-DiskImage ""%1""" >nul ECHO. ECHO The USB drive is now prepared for Legacy and UEFI boot (Macs Too) ECHO. ECHO. PAUSE EXIT :IMPROPERUSE CLS ECHO. ECHO ============================================= ECHO. ECHO IMPROPER USE DETECTED ECHO. ECHO CLOSE THE PROGRAM AND DRAG AND DROP THE ISO ECHO ONTO THE TOOL TO BEGIN ECHO. ECHO THIS TOOL CANNOT BE RUN DIRECTLY ECHO ============================================= ECHO. ECHO. ECHO. PAUSE EXIT :CHOOSEABORT ECHO. CHOICE /C YN /M "Would you like to abort? " IF %ERRORLEVEL%==1 GOTO ABORT ) ELSE ( GOTO INITMBR ) EXIT :NOTCOMPAT1 CLS CD /D %~dp0 IF EXIST "%~dp0TempUSB\*.*" DEL /S /Q "%~dp0TempUSB\*.*" >nul IF EXIST "%~dp0TempUSB" RD "%~dp0TempUSB" >nul POWERSHELL.EXE "Dismount-DiskImage ""%1""" >nul ECHO. ECHO ============================================== ECHO. ECHO INCOMPATIBLE ISO ECHO. ECHO THIS TOOL IS FOR ISO's CREATED BY PESE/XPE ECHO BOOT.WIM MUST BE PRESENT ECHO. ECHO ============================================== ECHO. ECHO. ECHO. PAUSE EXIT :NOTCOMPAT2 CLS CD /D %~dp0 IF EXIST "%~dp0TempUSB\*.*" DEL /S /Q "%~dp0TempUSB\*.*" >nul IF EXIST "%~dp0TempUSB" RD "%~dp0TempUSB" >nul POWERSHELL.EXE "Dismount-DiskImage ""%1""" >nul ECHO. ECHO ============================================== ECHO. ECHO INCOMPATIBLE ISO ECHO. ECHO THIS TOOL IS FOR ISO's CREATED BY PESE/XPE ECHO CdUsb.Y MUST BE PRESENT ECHO. ECHO ============================================== ECHO. ECHO. ECHO. PAUSE EXIT END LOCAL1 point
-
#include <WinAPIFiles.au3> #include <Array.au3> Local $aDriveInfo, $iLastDevNumber = -1 Local $aFixed = DriveGetDrive('FIXED'), $aRemovable = DriveGetDrive('REMOVABLE') Local $aDrives[ (IsArray($aFixed) ? $aFixed[0] : 0) + (IsArray($aRemovable) ? $aRemovable[0] : 0) ][3] Local $iDrive = 0 For $i = 1 To UBound($aFixed) - 1 $aDrives[$iDrive][0] = $aFixed[$i] $aDriveInfo = _WinAPI_GetDriveNumber($aFixed[$i]) If Not @error Then $aDrives[$iDrive][1] = $aDriveInfo[1] $aDrives[$iDrive][2] = $aDriveInfo[2] EndIf $iDrive += 1 Next For $i = 1 To UBound($aRemovable) - 1 $aDrives[$iDrive][0] = $aRemovable[$i] $aDriveInfo = _WinAPI_GetDriveNumber($aRemovable[$i]) If Not @error Then $aDrives[$iDrive][1] = $aDriveInfo[1] $aDrives[$iDrive][2] = $aDriveInfo[2] EndIf $iDrive += 1 Next _ArraySort($aDrives, 0, 0, 0, 1) Local $aDisks[ UBound($aDrives) ] [2] Local $sDrivesInfo = "Drive list :" & @CRLF Local $sOutput = "" For $i = 0 To UBound($aDrives) - 1 If IsNumber($aDrives[$i][1]) Then If $aDrives[$i][1] <> $iLastDevNumber Then $iLastDevNumber = $aDrives[$i][1] $aDisks[ $iLastDevNumber ][0] = "Disk " & $aDrives[$i][1] & " - " & _GetDiskNameByNumber($aDrives[$i][1]) & " - " EndIf $aDisks[ $iLastDevNumber ][1] &= $aDrives[$i][0] & ";" EndIf Next Redim $aDisks[$iLastDevNumber + 1][2] For $i = 0 To UBound($aDisks) - 1 $sOutput &= $aDisks[$i][0] & " [" $aSplit = StringRegExp($aDisks[$i][1], "[^;]+", 3) _ArraySort($aSplit) For $j = 0 To UBound($aSplit) - 1 $sOutput &= $aSplit[$j] & "\, " Next $sOutput &= "]" & @CRLF Next $sOutput = StringReplace($sOutput, ", ]", "]") MsgBox(0, "", $sOutput) Func _GetDiskNameByNumber($iDiskNumber) Local $iCount = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", "Count") Local $sDiskKey = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", String($iDiskNumber)) If @error Then Return SetError(1, 0, 0) Local $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "FriendlyName") If $sDiskName = "" Then $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "DeviceDesc") Return $sDiskName EndFunc1 point
-
You are responsible for the content you post on this site. Most of the site is a public forum and the private sections have only limited controls over those who can access them - this is particularly true of "Chat". So treat posting here as if you were speaking in a crowded room surrounded by strangers. Recent high-profile defamation events on other sites illustrate that there are ways in which third parties can force personal data, including contents of personal messages, to be released by site owners. Be careful - libelous/defamatory posts can and have landed members of these other sites in legal hot water. Your anonymity is not guaranteed in such situations. M231 point