-
Posts
92 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
bobomb's Achievements
-
meoit reacted to a post in a topic: WinNTSetup format helper tool (Is it possible to move the GUI out of this function easily? )
-
Scorpys reacted to a post in a topic: Autoit script doesn't run properly when started from BAT file
-
Scorpys reacted to a post in a topic: Autoit script doesn't run properly when started from BAT file
-
bobomb reacted to a post in a topic: I'm looking for an opinion on a specific scenario. (easy)
-
bobomb reacted to a post in a topic: I'm looking for an opinion on a specific scenario. (easy)
-
argumentum reacted to a post in a topic: I'm looking for an opinion on a specific scenario. (easy)
-
bobomb reacted to a post in a topic: Windows Media Player UDF GUI Control
-
Made some more improvements following your advice and adding some error checking... (Tested on Win10 Win11, will use @OSversion later check version and adjust accordingly) #NoTrayIcon #RequireAdmin #include <Constants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> Main() Func Main() Local _ $s_ScriptPath = PathRemoveTrail(@ScriptDir), _ $s_TempPath = PathRemoveTrail(TempLocation($s_ScriptPath)) If DriveGetType($s_TempPath) = "Fixed" Then Cleanup($s_TempPath, False) Local $s_WIMfile = FileOpenDialog( _ 'Select the boot.wim file to permanently inject drivers into', _ $s_ScriptPath & '\', _ 'Windows Image File (*.WIM)', _ $FD_FILEMUSTEXIST, _ 'boot.wim') If $s_WIMfile Then FileChangeDir($s_TempPath) If PathIsWritable($s_WIMfile) Then If PathIsWritable($s_TempPath) Then Local $s_DriverFolder = FileSelectFolder( _ 'Select the folder containing the drivers (Subfolders w/spaces Allowed)', _ $s_ScriptPath) If $s_DriverFolder Then If StringInStr($s_TempPath, $s_DriverFolder) Then MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'Working folder cannot be a subfolder of the driver folder!' & @CRLF & _ 'Move the drivers to a different folder.') Cleanup($s_TempPath) Else If CheckForSpace($s_WIMfile, $s_TempPath) Then MountWim($s_WIMfile, $s_TempPath) AddDrivers($s_DriverFolder, $s_TempPath) UnMountWim($s_TempPath) ExportWim($s_WIMfile, $s_TempPath, $s_ScriptPath) ; using $MB_OK (0) instead of 1 $MB_OKCANCEL MsgBox( _ BitOR($MB_OK, $MB_ICONINFORMATION), _ 'Process Complete...', _ 'Done.') Cleanup($s_TempPath) Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'Not enough free space!') Cleanup($s_TempPath) EndIf EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'No driver folder selected!') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'You do not have write access to %Temp%') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'You do not have write access boot.wim') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ "Process Aborted...", _ "No WIM selected!") Exit EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'Working folder must be located on a Fixed drive!' & @CRLF & @CRLF & _ 'Create ' & StringTrimRight(@ScriptName, 4) & '.ini and put it in' & @CRLF & _ 'in the same folder as the program. Example Below.' & @CRLF & @CRLF & _ '[Settings]' & @CRLF & _ 'TempDir=<put a valid path here>' & @CRLF & @CRLF & _ 'Set it to any path on a fixed drive.' & @CRLF & _ 'This is a requirement of DISM.') EndIf EndFunc ;==>Main Func TempLocation($s_ScriptPath) ; Read INI for temp path, if not exist defaults to system %Temp% ; Temp path cannot be inside driver folder or reCurse Local Static $s_TempPath = IniRead($s_ScriptPath & '\' & StringTrimRight(@ScriptName, 4) & '.ini', "Settings", "TempPath", @TempDir) If $s_TempPath = "" Then Return @ScriptDir Return $s_TempPath EndFunc ;==>TempLocation Func CheckForSpace($s_WIMfile, $s_TempPath) Local _ $s_AvailSpace = DriveSpaceFree($s_TempPath), _ $s_expandedWIMsize = ((FileGetSize($s_WIMfile) * 6) / 1048576) ; compresses to ~Approx 20% max, 5x + 1x for boot.wim copy If $s_AvailSpace > $s_expandedWIMsize Then Return True Return False EndFunc ;==>CheckForSpace Func MountWim($s_WIMfile, $s_TempPath) DirCreate($s_TempPath & '\TempWIM') DirCreate($s_TempPath & '\MountDir') CopyWIM($s_WIMfile, $s_TempPath & '\TempWIM') Local _ $s_DISMCommand = ' /Mount-Image /ImageFile:' & '"' & $s_TempPath & '\TempWIM\' & WIMFileOnly($s_WIMfile) & '"' & ' /Index:1 /MountDir:' & '"' & $s_TempPath & '\MountDir' & '"', _ $s_ProgTitle = 'Mounting Image', _ $s_ProgAction = 'Mounting boot.wim - ' DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') EndFunc ;==>MountWim Func AddDrivers($s_DriverFolder, $s_TempPath) RunWait(@ComSpec & ' /c DISM /Image:' & '"' & $s_TempPath & '\MountDir' & '"' & ' /Add-Driver /Driver:' & '"' & $s_DriverFolder & '"' & ' /ForceUnsigned /Recurse') ProcessWaitClose('DISM.EXE') EndFunc ;==>AddDrivers Func UnMountWim($s_TempPath, $s_singleProgBar = False) DISMProgress( _ ' /Unmount-Image /MountDir:' & '"' & $s_TempPath & '\MountDir' & '" /Commit', _ ; _ $s_DISMCommand 'Saving Image', _ ; _ $s_ProgTitle 'Saving and UnMounting Image - ', _ ; _ $s_ProgAction $s_singleProgBar, _ ; _ $s_singleProgBar 'UnMounting Image') ; _ $s_ProgTitle2 ProcessWaitClose('DISM.EXE') EndFunc ;==>UnMountWim Func Cleanup($s_TempPath, $b_Exit = True) If FileExists($s_TempPath & '\MountDir') Then DirRemove($s_TempPath & '\MountDir', $DIR_REMOVE) If FileExists($s_TempPath & '\TempWIM') Then DirRemove($s_TempPath & '\TempWIM', $DIR_REMOVE) If $b_Exit Then Exit EndFunc ;==>Cleanup Func WIMFileOnly($s_WIMfile) Local Static $s_WIMfilename = StringMid($s_WIMfile, StringInStr($s_WIMfile, "\", 2, -1) + 1) Return $s_WIMfilename EndFunc ;==>WIMFileOnly Func ExportWim($s_WIMfile, $s_TempPath, $s_ScriptPath) Local _ $s_ProgTitle = 'Exporting Image', _ $s_ProgAction = 'Cleaning Windows Image - ', _ $s_DestFolder = _FAF_DirectoryGetPathFromPath($s_WIMfile), _ $s_WIMname = WIMFileOnly($s_WIMfile), _ $s_DISMCommand = ' /Export-Image /SourceImageFile:' & '"' & $s_TempPath & '\TempWIM\' & $s_WIMname & '"' & ' /SourceIndex:1 /DestinationImageFile:' & '"' & $s_TempPath & '\' & $s_WIMname & '"' & ' /Compress:max' Local $s_NewWimFile = ($s_TempPath & '\' & $s_WIMname) DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') VerifyAndCopy($s_WIMfile, $s_WIMname, $s_TempPath, $s_DestFolder, $s_ScriptPath) EndFunc ;==>ExportWim Func VerifyAndCopy($s_OldWimFile, $s_WIMname, $s_TempPath, $s_DestFolder, $s_ScriptPath) Local $s_NewWimFile = ($s_TempPath & '\' & $s_WIMname) Local _ $i_NewWimSizeMB = (FileGetSize($s_NewWimFile) / 1048576), _ $i_OldWimSizeMB = (FileGetSize($s_OldWimFile) / 1048576), _ $i_FreeSpaceMB = DriveSpaceFree($s_DestFolder), _ $i_OkCancel = 0 If $i_NewWimSizeMB > ($i_FreeSpaceMB + $i_OldWimSizeMB) Then Do $i_OkCancel = MsgBox( _ BitOR($MB_OKCANCEL, $MB_ICONERROR), _ 'Not enough space!', _ 'There is not enough space to create the new boot.wim' & @CRLF & _ 'in its original location. Please select an alternate' & @CRLF & _ 'location to save the new file. The original boot.wim' & @CRLF & _ 'will not be updated or removed.') If $i_OkCancel = 2 Then MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'Cleaning up. No changes were' & @CRLF & _ 'made to your original files.') Cleanup($s_TempPath) EndIf $s_DestFolder = FileSelectFolder( _ 'Select an alternate location to save the new boot.wim', _ @ScriptDir) If Not $s_DestFolder = '' Then $i_FreeSpaceMB = DriveSpaceFree($s_DestFolder) Until $i_NewWimSizeMB < $i_FreeSpaceMB CopyWIM($s_NewWimFile, $s_DestFolder) FileDelete($s_NewWimFile) Else Sleep(500) FileDelete($s_OldWimFile) CopyWIM($s_NewWimFile, $s_DestFolder) FileDelete($s_NewWimFile) EndIf EndFunc ;==>VerifyAndCopy Func _FAF_DirectoryGetPathFromPath($s_Path) Return StringRegExpReplace($s_Path, "\\[^\\]*$", "") EndFunc ;==>_FAF_DirectoryGetPathFromPath Func PathRemoveTrail($sPath) If StringRight($sPath, 1) == '\' Then $sPath = StringTrimRight($sPath, 1) Return $sPath EndFunc ;==>PathRemoveTrail Func PathIsWritable($s_File) Local _ $a_Ret = DllCall('kernel32.dll', 'handle', 'CreateFileW', _ 'wstr', $s_File, _ 'dword', 2, _ 'dword', 7, _ 'struct*', 0, _ 'dword', 3, _ 'dword', 0x02000000, _ 'handle', 0) If @error Or $a_Ret[0] = Ptr(-1) Or $a_Ret[0] = 0 Then Return False DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $a_Ret[0]) Return True EndFunc ;==>PathIsWritable Func CopyWIM($fromFile, $todirectory) Local _ $i_OldWimFile = FileGetSize($fromFile), _ $FOF_RESPOND_YES = 16, _ $FOF_SIMPLEPROGRESS = 256 $s_WIMname = WIMFileOnly($fromFile) Local $s_NewWimFile = ($todirectory & '\' & $s_WIMname) If FileExists($s_NewWimFile) Then FileDelete($s_NewWimFile) Sleep(500) Local $winShell = ObjCreate("shell.application") $winShell.namespace($todirectory).CopyHere($fromFile, $FOF_RESPOND_YES) Do Sleep(10) Until FileGetSize($s_NewWimFile) = $i_OldWimFile EndFunc ;==>CopyWIM Func DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction, $s_singleProgBar = True, $i_alt = '') Local $i_DISM = Run(@ComSpec & ' /c DISM' & $s_DISMCommand, '', '', $STDERR_MERGED) ProgressOn($s_ProgTitle, $s_ProgAction, ' 0 Percent') Local _ $i_percent = 0, _ $i_value = 0, _ $i_a = 0, _ $s_Line, _ $s_Line1 While ProcessExists($i_DISM) $s_Line = StdoutRead($i_DISM) If @error Then ExitLoop If StringInStr($s_Line, '.0%') Then $s_Line1 = StringSplit($s_Line, '.') $i_value = StringRight($s_Line1[$s_Line1[0] - 1], 2) $i_value = StringStripWS($i_value, 7) EndIf If $i_value == "00" Then $i_value = 100 Sleep(50) If $i_percent <> $i_value Then ProgressSet($i_value, $s_ProgTitle, $s_ProgAction & $i_value & "%") $i_percent = $i_value EndIf If $s_singleProgBar = False Then ; is not single progress bar, capture second progress bar If $i_value = 100 Then $i_a += 1 If $i_a = 1 Then $i_value = 1 $s_ProgTitle = $i_alt EndIf EndIf ElseIf $i_value = 100 Then ; single progress bar completes here ExitLoop EndIf WEnd ProgressOff() EndFunc ;==>DISMProgress
-
Ok I think I got all the pathing issues sorted out. Changed the labels from h to s's How am I doing? #NoTrayIcon #RequireAdmin #include <Constants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> Main() Func Main($s_ScriptPath = PathRemoveTrail(@ScriptDir), $s_TempPath = PathRemoveTrail(TempLocation($s_ScriptPath))) Cleanup($s_TempPath, False) Local $s_WIMfile = FileOpenDialog( _ 'Select the boot.wim file to permanently inject drivers into', _ $s_ScriptPath & '\', _ 'Windows Image File (*.WIM)', _ $FD_FILEMUSTEXIST, _ 'boot.wim') If $s_WIMfile Then FileChangeDir($s_TempPath) If PathIsWritable($s_WIMfile) Then If PathIsWritable($s_TempPath) Then Local $s_DriverFolder = FileSelectFolder( _ 'Select the folder containing the drivers (Subfolders w/spaces Allowed)', _ $s_ScriptPath) If $s_DriverFolder Then If CheckForSpace($s_WIMfile, $s_TempPath) Then MountWim($s_WIMfile, $s_TempPath) AddDrivers($s_DriverFolder, $s_TempPath) UnMountWim($s_TempPath) ExportWim($s_WIMfile, $s_TempPath) ; using $MB_OK (0) instead of 1 $MB_OKCANCEL MsgBox( _ BitOR($MB_OK, $MB_ICONINFORMATION), _ 'Process Complete...', _ 'Done.') Cleanup($s_TempPath) Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'Not enough free space!') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'No driver folder selected!') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'You do not have write access to %Temp%') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ 'Process Aborted...', _ 'You do not have write access boot.wim') Cleanup($s_TempPath) EndIf Else MsgBox( _ BitOR($MB_OK, $MB_ICONERROR), _ "Process Aborted...", _ "No WIM selected!") Exit EndIf EndFunc ;==>Main Func TempLocation($s_ScriptPath) ; Read INI for temp path, if not exist defaults to system %Temp% ; Temp path cannot be inside driver folder or reCurse Local Static $s_TempPath = IniRead($s_ScriptPath & '\' & StringTrimRight(@ScriptName, 4) & '.ini', "Settings", "TempPath", @TempDir) Return $s_TempPath EndFunc ;==>TempLocation Func CheckForSpace($s_WIMfile, $s_TempPath) Local _ $s_AvailSpace = DriveSpaceFree($s_TempPath), _ $s_expandedWIMsize = ((FileGetSize($s_WIMfile) * 6) / 1048576) ; compresses to ~Approx 20% max, 5x + 1x for boot.wim copy If $s_AvailSpace > $s_expandedWIMsize Then Return True Else Return False EndIf EndFunc ;==>CheckForSpace Func MountWim($s_WIMfile, $s_TempPath) DirCreate($s_TempPath & '\TempWIM') DirCreate($s_TempPath & '\MountDir') CopyWIM($s_WIMfile, $s_TempPath & '\TempWIM') Local _ $s_DISMCommand = ' /Mount-Image /ImageFile:' & '"' & $s_TempPath & '\TempWIM\' & WIMFileOnly($s_WIMfile) & '"' & ' /Index:1 /MountDir:' & '"' & $s_TempPath & '\MountDir' & '"', _ $s_ProgTitle = 'Mounting Image', _ $s_ProgAction = 'Mounting boot.wim - ' DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') EndFunc ;==>MountWim Func AddDrivers($s_DriverFolder, $s_TempPath) RunWait(@ComSpec & ' /c DISM /Image:' & '"' & $s_TempPath & '\MountDir' & '"' & ' /Add-Driver /Driver:' & '"' & $s_DriverFolder & '"' & ' /ForceUnsigned /Recurse') ProcessWaitClose('DISM.EXE') EndFunc ;==>AddDrivers Func UnMountWim($s_TempPath, $s_singleProgBar = False) Local _ $s_ProgTitle = 'Saving Image', $s_ProgTitle2 = 'UnMounting Image', $s_ProgAction = 'Saving and UnMounting Image - ', _ $s_DISMCommand = ' /Unmount-Image /MountDir:' & '"' & $s_TempPath & '\MountDir' & '" /Commit' DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction, $s_singleProgBar, $s_ProgTitle2) ProcessWaitClose('DISM.EXE') EndFunc ;==>UnMountWim Func Cleanup($s_TempPath, $b_Exit = True) If FileExists($s_TempPath & '\MountDir') Then DirRemove($s_TempPath & '\MountDir', $DIR_REMOVE) If FileExists($s_TempPath & '\TempWIM') Then DirRemove($s_TempPath & '\TempWIM', $DIR_REMOVE) If $b_Exit Then Exit EndFunc ;==>Cleanup Func WIMFileOnly($s_WIMfile) Local Static $s_WIMfilename = StringMid($s_WIMfile, StringInStr($s_WIMfile, "\", 2, -1) + 1) Return $s_WIMfilename EndFunc ;==>WIMFileOnly Func ExportWim($s_WIMfile, $s_TempPath) Local _ $s_ProgTitle = 'Exporting Image', $s_ProgAction = 'Cleaning Windows Image - ', $s_DestFolder = _FAF_DirectoryGetPathFromPath($s_WIMfile), $s_WIMname = WIMFileOnly($s_WIMfile), _ $s_DISMCommand = ' /Export-Image /SourceImageFile:' & '"' & $s_TempPath & '\TempWIM\' & $s_WIMname & '"' & ' /SourceIndex:1 /DestinationImageFile:' & '"' & $s_TempPath & '\' & $s_WIMname & '"' & ' /Compress:max' DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') FileDelete($s_WIMfile) CopyWIM($s_TempPath & '\' & $s_WIMname, $s_DestFolder) FileDelete($s_TempPath & '\' & $s_WIMname) EndFunc ;==>ExportWim Func _FAF_DirectoryGetPathFromPath($s_Path) Return StringRegExpReplace($s_Path, "\\[^\\]*$", "") EndFunc ;==>_FAF_DirectoryGetPathFromPath Func PathRemoveTrail($sPath) If StringRight($sPath, 1) == '\' Then $sPath = StringTrimRight($sPath, 1) EndIf Return $sPath EndFunc ;==>PathRemoveTrail Func PathIsWritable($s_File) Local _ $a_Ret = DllCall('kernel32.dll', 'handle', 'CreateFileW', _ 'wstr', $s_File, _ 'dword', 2, _ 'dword', 7, _ 'struct*', 0, _ 'dword', 3, _ 'dword', 0x02000000, _ 'handle', 0) If @error Or $a_Ret[0] = Ptr(-1) Or $a_Ret[0] = 0 Then Return False DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $a_Ret[0]) Return True EndFunc ;==>PathIsWritable Func CopyWIM($fromFile, $todirectory) Local _ $FOF_RESPOND_YES = 16, _ $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($todirectory).CopyHere($fromFile, $FOF_RESPOND_YES) EndFunc ;==>CopyWIM Func DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction, $s_singleProgBar = True, $i_alt = '') Local _ $i_percent = 0, $i_value = 0, $i_a = 0, _ $s_DISM = Run(@ComSpec & ' /c DISM' & $s_DISMCommand, '', '', 2 + 4) ProgressOn($s_ProgTitle, $s_ProgAction, ' 0 Percent') While ProcessExists($s_DISM) $line = StdoutRead($s_DISM, 5) If StringInStr($line, '.0%') Then $line1 = StringSplit($line, '.') $i_value = StringRight($line1[$line1[0] - 1], 2) $i_value = StringStripWS($i_value, 7) EndIf If $i_value == "00" Then $i_value = 100 If @error Then ExitLoop Sleep(50) If $i_percent <> $i_value Then ProgressSet($i_value, $s_ProgTitle, $s_ProgAction & $i_value & "%") $i_percent = $i_value EndIf If $s_singleProgBar = False Then ; is not single progress bar, capture second progress bar If $i_value = 100 Then $i_a += 1 If $i_a = 1 Then $i_value = 1 $s_ProgTitle = $i_alt EndIf EndIf ElseIf $i_value = 100 Then ; single progress bar completes here ExitLoop EndIf WEnd ProgressOff() EndFunc ;==>DISMProgress
-
bobomb reacted to a post in a topic: Driver Injection for WinPE (For on the fly use between builds) - Suggestions
-
I am looking for pointers. I have been trying to follow advice up to this point that I have received. This is currently headless, only showing progress bars. I will try to have a dual progress bar GUI with current progress on top and overall progress on bottom. Advice on that is welcome. But mostly I am just looking for other set(s) of eyes to point out better ways to do things. It currently works fine. You select a boot.wim, select a folder with drivers, and it uses the DISM /add-driver /forceunsigned /recurse to add all drivers in the folder + subfolders (with spaces) to the boot.wim permanently. It captures progress from DISM. A couple snippets from around the forum have been adapted for use in, or are used, in this. I know its basic but the advice helps me learn faster. #NoTrayIcon #RequireAdmin #include <Constants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> Cleanup(False) Main() Func Main() Local $h_wimfile = FileOpenDialog('Select the boot.wim file to permanently inject drivers into', @WorkingDir & '\', 'Windows Image File (*.WIM)', 1, 'boot.wim') If $h_wimfile Then FileChangeDir(@ScriptDir) If PathIsWritable($h_wimfile) Then Local $h_folder = FileSelectFolder('Select the folder containing the drivers (Subfolders w/spaces Allowed)', @WorkingDir) If $h_folder Then FileChangeDir(@ScriptDir) MountWim($h_wimfile) FileChangeDir($h_folder) AddDrivers($h_folder) UnMountWim() ExportWim($h_wimfile) MsgBox(1, 'Process Complete...', 'Done.') Cleanup() Else MsgBox(1, 'Process Aborted...', 'No driver folder selected!') Cleanup() EndIf Else MsgBox(1, 'Process Aborted...', 'You do not have write access!') Cleanup() EndIf Else MsgBox(1, "Process Aborted...", "No WIM selected!") Exit EndIf EndFunc ;==>Main Func MountWim($h_wimfile) DirCreate(@ScriptDir & '\TempWIM') DirCreate(@ScriptDir & '\MountDir') CopyWIM($h_wimfile, @ScriptDir & '\TempWIM') Local $s_DISMCommand = ' /Mount-Image /ImageFile:' & '"' & @ScriptDir & '\TempWIM\' & WIMFileOnly($h_wimfile) & '"' & ' /Index:1 /MountDir:' & '"' & @ScriptDir & '\MountDir' & '"' Local $s_ProgTitle = 'Mounting Image', $s_ProgAction = 'Mounting boot.wim - ' DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') EndFunc ;==>MountWim Func AddDrivers($h_folder) RunWait(@ComSpec & ' /c DISM /Image:' & '"' & @ScriptDir & '\MountDir' & '"' & ' /Add-Driver /Driver:' & '"' & $h_folder & '"' & ' /ForceUnsigned /Recurse', @WorkingDir) EndFunc ;==>AddDrivers Func UnMountWim($s_commit = '/Commit') Local $s_DISMCommand = ' /Unmount-Image /MountDir:' & '"' & @ScriptDir & '\MountDir' & '" ' & $s_commit Local $s_ProgTitle = 'Saving Image', $s_ProgTitle2 = 'UnMounting Image', $s_ProgAction = 'Processing with ' & $s_commit & ' flag - ' Local $s_step = False DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction, $s_step, $s_ProgTitle2) ProcessWaitClose('DISM.EXE') EndFunc ;==>UnMountWim Func Cleanup($b_Exit = True) If FileExists(@ScriptDir & '\MountDir') Then DirRemove(@ScriptDir & '\MountDir', $DIR_REMOVE) If FileExists(@ScriptDir & '\TempWIM') Then DirRemove(@ScriptDir & '\TempWIM', $DIR_REMOVE) If $b_Exit Then Exit EndFunc ;==>Cleanup Func WIMFileOnly($h_wimfile) Local Static $h_wimfilename = StringMid($h_wimfile, StringInStr($h_wimfile, "\", 2, -1) + 1) Return $h_wimfilename EndFunc ;==>WIMFileOnly Func ExportWim($h_wimfile) Local $s_DISMCommand = ' /Export-Image /SourceImageFile:' & '"' & @ScriptDir & '\TempWIM\' & WIMFileOnly($h_wimfile) & '"' & ' /SourceIndex:1 /DestinationImageFile:' & '"' & @ScriptDir & '\' & WIMFileOnly($h_wimfile) & '"' & ' /Compress:max' Local $s_ProgTitle = 'Exporting Image', $s_ProgAction = 'Cleaning Windows Image', $s_DestFolder = _FAF_DirectoryGetPathFromPath($h_wimfile) DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction) ProcessWaitClose('DISM.EXE') FileDelete($h_wimfile) CopyWIM(@ScriptDir & '\' & WIMFileOnly($h_wimfile), $s_DestFolder) FileDelete(@ScriptDir & '\' & WIMFileOnly($h_wimfile)) EndFunc ;==>ExportWim Func _FAF_DirectoryGetPathFromPath($s_Path, $i_Backslash = 1) If $i_Backslash Then Return StringRegExpReplace($s_Path, "(^.*\\)(.*)", "\1") Return StringRegExpReplace($s_Path, "\\[^\\]*$", "") EndFunc ;==>_FAF_DirectoryGetPathFromPath 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 CopyWIM($fromFile, $todirectory) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($todirectory).CopyHere($fromFile, $FOF_RESPOND_YES) EndFunc ;==>CopyWIM Func DISMProgress($s_DISMCommand, $s_ProgTitle, $s_ProgAction, $s_step = True, $i_alt = '') Local $i_percent = 0, $i_value = 0, $i_a = 0 Local $s_DISM = Run(@ComSpec & ' /c DISM' & $s_DISMCommand, @ScriptDir, '', 2 + 4) ProgressOn($s_ProgTitle, $s_ProgAction, ' 0 Percent') While ProcessExists($s_DISM) $line = StdoutRead($s_DISM, 5) If StringInStr($line, '.0%') Then $line1 = StringSplit($line, '.') $i_value = StringRight($line1[$line1[0] - 1], 2) $i_value = StringStripWS($i_value, 7) EndIf If $i_value == "00" Then $i_value = 100 If @error Then ExitLoop Sleep(50) If $i_percent <> $i_value Then ProgressSet($i_value, $s_ProgTitle, $s_ProgAction & $i_value & "%") $i_percent = $i_value EndIf If $s_step = False Then If $i_value = 100 Then $i_a += 1 If $i_a = 1 Then $i_value = 1 $s_ProgTitle = $i_alt EndIf EndIf ElseIf $i_value = 100 Then ExitLoop EndIf WEnd ProgressOff() EndFunc ;==>DISMProgress
-
bobomb reacted to a post in a topic: Are there any cars that have two separate fuel tanks?
-
He is trying to tell you to post something that runs, so if you dont want to post your entire script at least make an example script that RUNS with the same problem so people can actually help you.. how can anyone else guess what is required to get that running to the point where they can even see the same error?
-
bobomb reacted to a post in a topic: FAQ - Updated - Please Read Before Posting
-
EDIT: I just found this issue reported in the copy UDF thread as well. It seems archived at this point.. Is anyone able to look at the pointer call to see if this is the DLL or not? Same program I was getting help with (BurnTool) GUI, Progress etc.. But this issue is unrelated, only the program itself is the same, so I thought it prudent to open a thread for this specific issue.. As the title states, I can compile this as x86 and it works fine.. Once compiled x64 the copy GUI opens and then crashes before anything starts to copy.. (Works x64 on Win7 but NOT on Win10 or Win11) This uses @Yashied's Copy UDF: https://www.autoitscript.com/forum/topic/121833-copy-udf/ (This is where the DLL's and UDF came from but if you dont want to use what I provided in the 7z you can get them yourself they are located here) Copy.dll is present for x86 during execution... Copy_x64.dll is present for x64 during execution... Subfolder Copy\Images\ is used for simple GUI... A 7z is attached with test files and a test ISO. The TestISO.ISO file appears to contain data however ALL files with the exception of the autorun.ico file are really just TEXT files filled with the words testtesttest repeatedly.. So bootmgr.exe is a renamed text file you can see with a text editor or by renaming it back. This is done for the purpose of not pissing off MS (or anyone else ) and still having something to test with for anyone willing to help.. If you are going to try and Run the software this is a USB or Fixed drive burning tool.. Be aware that it does format drives you tell it to, and then it copies files from the ISO to the USB/Fixed drive you choose. You will need a blank USB to test (or one you are willing to format). If you drop the extracted files into C:\bobomb\ you will not have to alter the code to run the initial x86 vs x64 testing (paths are hardcoded for copy UDF and GUI files) .. Script posted for visibility but included in the attached 7z #NoTrayIcon #RequireAdmin #Tidy_Parameters=/sf #Region #### autoit udfs #### #include <Array.au3> #include <ColorConstants.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WinAPIFiles.au3> #include <WinAPIInternals.au3> #include <WindowsConstants.au3> #EndRegion #### autoit udfs #### #Region #### user udfs #### #include 'C:\Bobomb\Copy\UDF\Copy.au3' #EndRegion #### user udfs #### #Region #### globals #### Global Const _ ; GUI_SwitchGUI $GA_DELETEOLDGUINO = 0, _ $GA_DELETEOLDGUIYES = 1, _ $GA_DISABLEOLDGUINO = 0, _ $GA_DISABLEOLDGUIYES = 1, _ $GA_HIDEOLDGUINO = 0, _ $GA_HIDEOLDGUIYES = 1, _ $GA_ONEVENTMODENO = 0, _ $GA_ONEVENTMODEYES = 1 Global $h_MainGUI = 0 ; main gui for GUI_SwitchGUI function Global _ $id_DiskList = 0, _ $id_BurnBtn = 0 Global _ $s_BootDrive = '', _ $s_DataDrive = '', _ $s_MountedDrive = '' #EndRegion #### globals #### Opt("GUIOnEventMode", 1) Initialise() ; _ run program pre checks GUI_CreateGUI() ; _ create the main program gui Func BootWim_Check() ; check for the boot wim file If Not FileExists($s_MountedDrive & '\sources\boot.wim') Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "BOOT.WIM NOT DETECTED!!!" & @CRLF & "This tool is designed for SE" & @CRLF & "and XPE projects only.") GUI_CloseGUI() EndIf EndFunc ;==>BootWim_Check Func BootWim_GetSize() ; get the boot wim size and add 200 megabytes for headroom on boot partition Return Round((FileGetSize($s_MountedDrive & '\sources\boot.wim') + 209715200) / 1048576) EndFunc ;==>BootWim_GetSize Func BurnPressed() ; start the burn process Local $s_DiskNumber = StringRegExp(GUICtrlRead($id_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH) If $s_DiskNumber = "" Then MsgBox( _ $MB_ICONERROR, _ ; it is possible to bug the GUI and make the buttons appear by pressing + or - on tree then refresh "Attention: ", _ "No disk is selected!") Buttons_Disable() Else Local $s_DiskNumber = StringRegExp(GUICtrlRead($id_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0] If @error Then MsgBox( _ $MB_ICONERROR, _ "Notice: ", _ "An error occured retrieving the disk number") Else If MsgBox( _ BitOR($MB_TOPMOST, $MB_ICONWARNING, $MB_YESNO, $MB_DEFBUTTON2), _ 'This will FORMAT Disk ' & $s_DiskNumber, _ 'ALL DATA WILL BE ERASED FROM DISK ' & $s_DiskNumber & @CRLF & 'Are you sure you want to proceed?') = $IDYES Then GUISetState(@SW_HIDE) ProgressOn("BurnTool (XPE/SE) v2.0", "Creating Bootable Media...", "0%") Format_Prepare($s_DiskNumber) ProgressSet(5 & "%", "Formatting Disk " & $s_DiskNumber) Format_Run() ProgressSet(100, "Format Complete", "Begin Filecopy...") ProgressOff() MsgBox(1, "", $s_MountedDrive & " - " & $s_BootDrive & ':') Copy_PartitionFiles($s_MountedDrive, $s_BootDrive & ':') Copy_PartitionFiles($s_MountedDrive, $s_DataDrive & ':', "Data") MsgBox( _ $MB_ICONINFORMATION, _ "Process Complete", _ " Enjoy! ") GUI_CloseGUI() EndIf EndIf EndIf EndFunc ;==>BurnPressed Func Buttons_Disable() ; disable the gui buttons GUICtrlSetState($id_BurnBtn, $GUI_DISABLE) EndFunc ;==>Buttons_Disable Func Buttons_Enable() ; enable the gui buttons GUICtrlSetState($id_BurnBtn, $GUI_ENABLE) EndFunc ;==>Buttons_Enable Func CacheFolder_DeleteFiles() ; remove the cache folder and exit program if specified If FileExists(CacheFolder_GetPath()) Then DirRemove(CacheFolder_GetPath(), $DIR_REMOVE) EndFunc ;==>CacheFolder_DeleteFiles Func CacheFolder_GetPath() ; get the path to the cache folder, returns with trailing '\' Local Static $s_CachePath = IniRead(@WorkingDir & '\USBTool.ini', "Settings", "CachePath", @WorkingDir & '\cache') & '\' Return $s_CachePath EndFunc ;==>CacheFolder_GetPath Func Copy_FilesFolders($s_Title, ByRef $as_Files, $s_Source, $s_Destination, $h_OldGui, $b_RemoveRO = False) ; copy the required files to the selected partition Local _ $i_Error = 0, _ $i_Extended = 0 Local $v_Return = '' If $s_Source <> '' And $s_Destination <> '' Then ; check for an array of files and folders If IsArray($as_Files) Then $s_Destination = StringRegExpReplace($s_Destination, '\\+$', '') ; check for destinaation and create if missing If Not FileExists($s_Destination) Then DirCreate($s_Destination) ; check if the destination exists If FileExists($s_Destination) Then ; make sure there's no trailing '\' then add one $s_Source = StringRegExpReplace($s_Source, '\\+$', '') & '\' $s_Destination = StringRegExpReplace($s_Destination, '\\+$', '') & '\' ; the dll file(s) need to be in the same dir as the script. ; if you dont want this, then use fileinstall to install it ; where you have write access x64 = Copy_x64.dll, x86 = Copy.dll If _Copy_OpenDll() Then #Region #### create gui #### Local _ $i_FontSize = 16, _ $i_FontWeight = 800, _ $i_PbarWidth = 400 Local _ $s_FontName = 'Trebuchet MS', _ $s_FontColour = $COLOR_WHITE, _ $s_BkColour = $GUI_BKCOLOR_TRANSPARENT Local $h_CopyGUI = GUICreate('Copy GUI', 634, 176, 1344, 367, $WS_POPUP, $WS_EX_LAYERED) GUICtrlCreatePic('C:\Bobomb\Copy\Images\GUIBack.bmp', 0, 0, 633, 175) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreatePic('C:\Bobomb\Copy\Images\GUIBanner.bmp', 0, 0, 633, 32) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel($s_Title, 5, 5, 561, 25) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) $i_FontSize = 10 $s_FontName = 'MS Sans Serif' GUICtrlCreateLabel('Source :', 10, 45, 85, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) Local $id_Source_lbl = GUICtrlCreateLabel('', 100, 45, 520, 17, $DT_END_ELLIPSIS) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlCreateLabel('Destination:', 10, 69, 85, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) Local $id_Destination_lbl = GUICtrlCreateLabel('', 100, 69, 520, 17, $DT_END_ELLIPSIS) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) $i_FontSize = 8 Local $id_Action_lbl = GUICtrlCreateLabel('', 72, 110, 72, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) Local $id_Info_lbl = GUICtrlCreateLabel('', 148, 110, 335, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlCreateLabel('File', 72, 129, 35, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_PbarBack.bmp', 115, 130, 403, 14) GUICtrlSetState(-1, $GUI_DISABLE) Local $id_CopyProgBar = GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_Pbar.bmp', 116, 133, 1, 8) Local $id_FileSize_lbl = GUICtrlCreateLabel('23', 522, 129, 100, 14) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlCreateLabel('Total', 72, 149, 35, 17) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_PbarBack.bmp', 115, 150, 403, 14) GUICtrlSetState(-1, $GUI_DISABLE) Local $id_totalProgBar = GUICtrlCreatePic('C:\Bobomb\Copy\Images\CopyGUI_Pbar.bmp', 116, 153, 1, 8) Local $id_TotalFileCount_lbl = GUICtrlCreateLabel('0/' & $as_Files[0], 522, 150, 100, 14) GUICtrlSetBkColor(-1, $s_BkColour) GUICtrlSetColor(-1, $s_FontColour) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) ; set the GUI transparency ;_WinAPI_SetLayeredWindowAttributes($h_CopyGUI, 0x010101, 200) #EndRegion #### create gui #### ; change the gui GUI_SwitchGUI($h_CopyGUI, $h_OldGui, Default, $GA_DISABLEOLDGUIYES, $GA_HIDEOLDGUIYES) GUI_CentreGUI($h_OldGui, $h_CopyGUI) GUISetState(@SW_SHOW, $h_CopyGUI) Local $ai_State = 0 ; loop through the files and copy them For $i = 1 To $as_Files[0] ; check if file or dir and change copy mode If _WinAPI_PathIsDirectory($s_Source & $as_Files[$i]) Then _Copy_CopyDir($s_Source & $as_Files[$i], $s_Destination & $as_Files[$i], $COPY_FILE_NO_BUFFERING, $COPY_OVERWRITE_YES) Else _Copy_CopyFile($s_Source & $as_Files[$i], $s_Destination & $as_Files[$i], $COPY_FILE_NO_BUFFERING) EndIf GUICtrlSetData($id_Action_lbl, Copy_GetStatus()) ; status While 1 $ai_State = _Copy_GetState() If $ai_State[0] Then If GUICtrlRead($id_Source_lbl) <> $ai_State[6] Then GUICtrlSetData($id_Source_lbl, $ai_State[6]) If GUICtrlRead($id_Destination_lbl) <> $ai_State[7] Then GUICtrlSetData($id_Destination_lbl, $ai_State[7]) Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar, $ai_State[3], $ai_State[4]) ; file copy progress bar GUICtrlSetData($id_FileSize_lbl, _WinAPI_StrFormatByteSize($ai_State[3]) & '/' & _WinAPI_StrFormatByteSize($ai_State[4])) ; file copy transferred Else Switch $ai_State[5] Case 0 ; all OK Case 1235 ; ERROR_REQUEST_ABORTED ;~ Case Else ; add the error file\dir and error code to the array $i_Error = 7 $i_Extended += 1 Copy_UpdateErrorArray($ai_State[6], $ai_State[5]) EndSwitch Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar, 100, 100) ; _ set file copy progress bar Copy_SetTotalProgress($h_CopyGUI, $id_totalProgBar, $i, $as_Files[0]) ;_ set total progress bar GUICtrlSetData($id_TotalFileCount_lbl, $i & '/' & $as_Files[0]) ; set total copy count ExitLoop EndIf Sleep(80) WEnd Next ; reset the controls GUICtrlSetData($id_Source_lbl, '') GUICtrlSetData($id_Destination_lbl, '') GUICtrlSetData($id_Action_lbl, '') Copy_SetFileProgress($h_CopyGUI, $id_CopyProgBar) Copy_SetFileProgress($h_CopyGUI, $id_totalProgBar) GUICtrlSetData($id_FileSize_lbl, '') GUICtrlSetData($id_TotalFileCount_lbl, '') If $b_RemoveRO Then ; remove read only attributes from the destination GUICtrlSetData($id_Action_lbl, 'Removing') GUICtrlSetData($id_Info_lbl, 'Read Only attributes on ' & $s_Destination) FileSetAttrib($s_Destination, '-R', $FT_RECURSIVE) EndIf GUI_SwitchGUI($h_OldGui, $h_CopyGUI, Default, Default, $GA_DELETEOLDGUIYES) If Not _Copy_CloseDll() Then ; error closing the copy dll $i_Error = 6 $v_Return = 'Unable to close the dll file: ' & Copy_GetDllName() EndIf Else ; unable to open copy dll $i_Error = 4 $v_Return = 'Unable to find the dll file: ' & Copy_GetDllName() EndIf Else ; unable to create destination $i_Error = 3 $v_Return = 'Unable to create destination: ' & $s_Destination EndIf Else ; array not valid $i_Error = 2 $v_Return = '$as_Files is not an array. No files\folders to copy' EndIf Else $i_Error = 1 $v_Return = 'Missing Source or Destination values' EndIf Return SetError($i_Error, $i_Extended, $v_Return) EndFunc ;==>Copy_FilesFolders Func Copy_GetDllName() ; get the dll name for Copy_FilesFolders Return (@AutoItX64 = 0) ? ('Copy.dll') : ('Copy_x64.dll') EndFunc ;==>Copy_GetDllName Func Copy_GetStatus() ; get the file\folder current action for Copy_FilesFolders Return (_Copy_GetAction() = 0) ? ('Copying File') : ('Moving File') EndFunc ;==>Copy_GetStatus Func Copy_PartitionFiles($s_Source, $s_Destination, $s_Partition = 'Boot') ; set the required files and partition for Copy_FilesFolders Local $s_BootList = 'boot;efi;sources;bootmgr;bootmgr.efi;bootmgr.exe;menu.lst' Local $s_Mask = $s_BootList If $s_Partition = 'Data' Then $s_Mask = '*|' & $s_BootList ; search the source for specified files only Local $as_Files = _FileListToArrayRec($s_Source, $s_Mask, $FLTAR_FILESFOLDERS, $FLTAR_NORECUR, $FLTAR_SORT) Local $v_Ret = Copy_FilesFolders('Copying ' & $s_Partition & ' Files', $as_Files, $s_Source, $s_Destination, $h_MainGUI) If @error Then If @extended Then If MsgBox( _ BitOR($MB_ICONERROR, $MB_YESNO, $MB_DEFBUTTON2), _ 'Copy Error(s): ' & @extended, _ 'Error(s) Occurred during the copy process ' & @CRLF & ' Do you want to view the file names?') = $IDYES Then _ _ArrayDisplay(Copy_UpdateErrorArray(), 'Copy Errors', '', $ARRAYDISPLAY_COLALIGNLEFT, Default, 'Path|ErrorCode') Else MsgBox( _ $MB_ICONERROR, _ 'Error occured', _ $v_Ret) EndIf Else MsgBox( _ $MB_ICONINFORMATION, _ $s_Partition & ' Partition', _ 'All ' & $s_Partition & ' files were successfully copied to :- ' & @CRLF & $s_Destination) EndIf EndFunc ;==>Copy_PartitionFiles Func Copy_SetFileProgress($h_Gui, $id_Ctrl, $i_Current = 0, $i_Total = 0) ; set the file copy progress bar for Copy_FilesFolders Local $ai_Pos = ControlGetPos($h_Gui, '', $id_Ctrl) Local $i_Value = 0 If $i_Current <> 0 Then $i_Value = (Round($i_Current / $i_Total * 100) * 4) GUICtrlSetPos($id_Ctrl, $ai_Pos[0], $ai_Pos[1], $i_Value, $ai_Pos[3]) EndFunc ;==>Copy_SetFileProgress Func Copy_SetTotalProgress($h_Gui, $id_Ctrl, $i_Current = 0, $i_Total = 0) ; set the total progress bar for Copy_FilesFolders Local $ai_Pos = ControlGetPos($h_Gui, '', $id_Ctrl) Local $i_Value = 0 If $i_Current <> 0 Then $i_Value = (Round($i_Current / $i_Total * 100) * 4) GUICtrlSetPos($id_Ctrl, $ai_Pos[0], $ai_Pos[1], $i_Value, $ai_Pos[3]) EndFunc ;==>Copy_SetTotalProgress Func Copy_UpdateErrorArray($s_Path = '', $i_ErrorCode = 0) Local Static $as_Error[1][2] = [[0, '']] If $s_Path <> '' Then $as_Error[0][0] = _ArrayAdd($as_Error, $s_Path & '|' & _WinAPI_GetErrorMessage($i_ErrorCode)) Else Return $as_Error EndIf EndFunc ;==>Copy_UpdateErrorArray Func DiskList_GetDrives() ; get the system drives Local Const $WBEMFLAGRETURNIMMEDIATELY = 0x10 Local Enum _ $Unknown, _ $NoRootDirectory, _ $RemovableDisk, _ $LocalDisk, _ $NetworkDrive, _ $CompactDisk, _ $RAMDisk Local $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") If IsObj($o_WMIService) Then Local $s_Query = "SELECT * FROM Win32_DiskDrive" Local $o_DiskDrives = $o_WMIService.ExecQuery($s_Query, "WQL", $WBEMFLAGRETURNIMMEDIATELY) If IsObj($o_DiskDrives) Then Local $o_Partitions = 0 Local $o_LogicalDisks = 0 For $o_DiskDrive In $o_DiskDrives $h_Parent = GUICtrlCreateTreeViewItem("Disk " & $o_DiskDrive.Index & " [" & $o_DiskDrive.Model & "]", $id_DiskList) GUICtrlSetOnEvent(-1, 'Buttons_Enable') _GUICtrlTreeView_SetIcon($id_DiskList, $h_Parent, "shell32.dll", 15) $s_Query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $o_DiskDrive.DeviceId & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" $o_Partitions = $o_WMIService.ExecQuery($s_Query) If IsObj($o_Partitions) Then For $o_Partition In $o_Partitions $s_Query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $o_Partition.DeviceId & "'} WHERE AssocClass = Win32_LogicalDiskToPartition" $o_LogicalDisks = $o_WMIService.ExecQuery($s_Query) For $o_LogicalDisk In $o_LogicalDisks If $o_LogicalDisk.drivetype = $RemovableDisk Or $o_LogicalDisk.drivetype = $LocalDisk Then GUICtrlCreateTreeViewItem('(' & $o_LogicalDisk.DeviceId & '\) ' & $o_LogicalDisk.Volumename, $h_Parent) GUICtrlSetOnEvent(-1, 'Buttons_Disable') _GUICtrlTreeView_SetIcon($id_DiskList, -1, "shell32.dll", 7) EndIf Next Next Else ; add error info here EndIf Next Else ; add error info here EndIf Else ; add error info here EndIf EndFunc ;==>DiskList_GetDrives Func DiskList_Load() ; load the system drives _GUICtrlTreeView_BeginUpdate($id_DiskList) _GUICtrlTreeView_DeleteAll($id_DiskList) DiskList_GetDrives() If _GUICtrlTreeView_GetCount($id_DiskList) > 2 Then _GUICtrlTreeView_Sort($id_DiskList) _GUICtrlTreeView_Expand($id_DiskList) _GUICtrlTreeView_EndUpdate($id_DiskList) Buttons_Disable() EndFunc ;==>DiskList_Load Func Diskpart_CreateScriptFile($s_File, $s_Data) ; create the diskpart script file Local $h_CacheFile = FileOpen(CacheFolder_GetPath() & $s_File, $FO_OVERWRITE) FileWrite($h_CacheFile, $s_Data) FileClose($h_CacheFile) EndFunc ;==>Diskpart_CreateScriptFile Func DriveLetters_GetAvailable() ; get the available system drive letters Local $as_DriveList = DriveGetDrive($DT_ALL) Local _ $s_DriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ", _ $s_AvailableDriveLetters If @error Then ; An error occurred when retrieving the drives. MsgBox( _ BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), _ "", _ "An Error Occurred! Unable to retrieve available drive letters! Exiting Program...") GUI_CloseGUI() Else ; loop through the enumerated drives and remove those in use Local $s_DriveLetter = '' For $i = 1 To $as_DriveList[0] $s_DriveLetter = StringLeft(StringUpper($as_DriveList[$i]), 1) $s_DriveLetters = StringReplace($s_DriveLetters, $s_DriveLetter, "") Next EndIf ; get an array of available drive letters $s_AvailableDriveLetters = StringSplit($s_DriveLetters, "") $s_BootDrive = $s_AvailableDriveLetters[1] ; Get first available letter (returns without ':\', needed for DiskPart assign letter) $s_DataDrive = $s_AvailableDriveLetters[2] ; Get second available letter (returns without ':\', needed for DiskPart assign letter) ;$s_DataDrive = $s_AvailableDriveLetters[1] ; Get second available letter EndFunc ;==>DriveLetters_GetAvailable Func Format_Prepare($s_Drive) ; prepare the diskpart script files DriveLetters_GetAvailable() Diskpart_CreateScriptFile('clean.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'clean' & @CRLF & 'Exit') Diskpart_CreateScriptFile('attrib.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit') Diskpart_CreateScriptFile('scrubber.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=scrubber' & @CRLF & 'Exit') Diskpart_CreateScriptFile('convert.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'convert mbr' & @CRLF & 'Exit') Diskpart_CreateScriptFile('initdata.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'shrink minimum=' & BootWim_GetSize() & @CRLF & 'format quick fs=ntfs label="WinPE Data"' & @CRLF & 'assign letter=' & $s_DataDrive & @CRLF & 'Exit') Diskpart_CreateScriptFile('initboot.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=fat32 label="BOOTFILES"' & @CRLF & 'assign letter=' & $s_BootDrive & @CRLF & 'Active' & @CRLF & 'Exit') EndFunc ;==>Format_Prepare Func Format_Run() ; format the selected drive Local $as_DiskPart[8][2] = [ _ [7, 0], _ ["Cleaning Drive", 'clean.dat'], _ ["Cleaning Drive", 'scrub.dat'], _ ["Cleaning Drive", 'clean.dat'], _ ["Resetting Disk Attributes", 'attrib.dat'], _ ["Converting Layout to MBR", 'convert.dat'], _ ["Creating Data Partition", 'initdata.dat'], _ ["Creating Boot Partition", 'initboot.dat'] _ ] Local $s_Program = @ComSpec & ' /c diskpart /s ' & '"' & CacheFolder_GetPath() For $i = 1 To $as_DiskPart[0][0] ProgressSet($i * 13 & "%", $as_DiskPart[$i][0]) RunWait($s_Program & $as_DiskPart[$i][1] & '"', @WorkingDir, @SW_HIDE) Sleep(750) Next EndFunc ;==>Format_Run ; #FUNCTION# ==================================================================================================================== ; Name ..........: GUI_CentreGUI ; Description ...: Centre a child gui to it's parent using the parent's co-ordinates ; Syntax ........: GUI_CentreGUI($h_OldGui, $h_Child) ; Parameters ....: $h_OldGui - a handle value. Handle of the parent gui ; $h_Child - a handle value. Handle of the child gui ; Return values .: None ; Author ........: Benners ; Modified ......: ; =============================================================================================================================== Func GUI_CentreGUI($h_OldGui, $h_Child) ; centre a child gui to it's parent Local _ $ai_ParentPos = WinGetPos($h_OldGui, ''), _ ; _ get the position of the parent gui $ai_ChildSize = WinGetClientSize($h_Child, '') ; _ get the size of the viewer gui Local _ $i_Xcord = $ai_ParentPos[0] + ($ai_ParentPos[2] / 2) - ($ai_ChildSize[0] / 2), _ $i_Ycord = $ai_ParentPos[1] + ($ai_ParentPos[3] / 2) - ($ai_ChildSize[1] / 2) WinMove($h_Child, '', $i_Xcord, $i_Ycord) ; move the child gui to the centre of the parent gui EndFunc ;==>GUI_CentreGUI Func GUI_CloseGUI() ; close the gui ISO_Unmount() CacheFolder_DeleteFiles() Exit EndFunc ;==>GUI_CloseGUI Func GUI_CreateGUI() ; draw the gui $h_MainGUI = GUICreate('BurnTool (XPE/SE) v2.0', 300, 287) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CloseGUI") GUISetIcon(@WorkingDir & '\USBTool.ico', 1) GUISetBkColor(0x797979) GUICtrlCreateLabel('Select a disk to use...', 20, 10, 280) $id_DiskList = GUICtrlCreateTreeView(10, 30, 280, 150) DiskList_Load() GUICtrlCreateButton('Refresh List', 110, 187, 80, 25) GUICtrlSetOnEvent(-1, "DiskList_Load") GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('________________________________________', 30, 210, 280, 30) $id_BurnBtn = GUICtrlCreateButton('Burn', 90, 232, 120, 40) GUICtrlSetOnEvent(-1, "BurnPressed") GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() ; Just idle around While 1 Sleep(10) WEnd EndFunc ;==>GUI_CreateGUI ; #FUNCTION# ==================================================================================================================== ; Name ..........: GUI_SwitchGUI ; Description ...: Switches the current active window to be associated with running GUI functions. ; Syntax ........: GUI_SwitchGUI($h_NewGui, $h_OldGui[, $i_EventMode = Default[, $i_DisableOldGui = Default[, $i_HideOldGui = Default[, ; $i_DeleteOldGui = Default]]]]) ; Parameters ....: $h_NewGui - The handle of the gui that is to be the current window ; $h_OldGui - The handle of the gui that is to relinquish control ; $i_EventMode - [optional] an integer value. Sets the Opt("GUIOnEventMode") for notifications (enable\disable) ; Default is disabled ($GA_ONEVENTMODENO) ; $i_DisableOldGui - [optional] an integer value. Changes the state of the $h_OldGui window (enable\disable) ; Default is enabled ($GA_DISABLEOLDGUINO) ; $i_HideOldGui - [optional] an integer value. Hide the old gui ; $i_DeleteOldGui - [optional] an integer value. Deletes the $h_OldGui window and all controls that it contains (yes\no) ; Default is no ($GA_DELETEOLDGUINO) ; Return values .: None ; Author ........: Benners ; Modified ......: ; Remarks .......: ; =============================================================================================================================== Func GUI_SwitchGUI($h_NewGui, $h_OldGui, $i_EventMode = Default, $i_DisableOldGui = Default, $i_HideOldGui = Default, $i_DeleteOldGui = Default) If $i_EventMode = Default Then $i_EventMode = $GA_ONEVENTMODENO If $i_DisableOldGui = Default Then $i_DisableOldGui = $GA_DISABLEOLDGUINO If $i_HideOldGui = Default Then $i_HideOldGui = $GA_HIDEOLDGUINO If $i_DeleteOldGui = Default Then $i_DeleteOldGui = $GA_DELETEOLDGUINO Opt("GUIOnEventMode", $i_EventMode) ;_ set on event mode (disabled or enabled) GUISwitch($h_NewGui) ;_ switch control to the new GUI. GUISetState(@SW_ENABLE, $h_NewGui) ;_ enable the new gui GUISetState(@SW_RESTORE, $h_NewGui) ;_ undo a window minimization GUISetState(@SW_SHOW, $h_NewGui) ;_ show the gui If $i_DisableOldGui Then GUISetState(@SW_DISABLE, $h_OldGui) ;_ disable the old GUI. If $i_HideOldGui Then GUISetState(@SW_HIDE, $h_OldGui) ; _ hide the old gui If $i_DeleteOldGui Then GUIDelete($i_DeleteOldGui) ;_ destroy the old gui EndFunc ;==>GUI_SwitchGUI Func Initialise() ; run pre checks before program starts ISO_CheckWasDropped() ; _ check for a cmdline argument (iso file was dropped on the exe) ISO_Mount() ; _ mount the dropped iso $s_MountedDrive = ISO_GetDriveLetter() ; _ get the drive letter for the mounted iso, returns without trailing '\' BootWim_Check() ; _ check for the bootwim file on the mounted drive CacheFolder_DeleteFiles() ; _ delete the cache folder DirCreate(CacheFolder_GetPath()) ; _ create the cache folder EndFunc ;==>Initialise Func ISO_CheckWasDropped() ; check that an iso was dropped on to the exe If $CmdLine[0] = 0 Then ; no file was dropped or passed via the command line MsgBox( _ $MB_ICONERROR, _ "Attention: ", _ "This program cannot be run directly!" & @CRLF & "Please drag an ISO onto the program to begin...") GUI_CloseGUI() EndIf EndFunc ;==>ISO_CheckWasDropped Func ISO_GetDriveLetter() ; get the drive letter of the mounted iso, returns with trailing '\' Local $s_MarkerFile = 'BOOTMGR' Local $s_IsoDrive = '' Local $as_CDROM = DriveGetDrive($DT_CDROM) For $i = 1 To $as_CDROM[0] If FileExists($as_CDROM[$i] & '\' & $s_MarkerFile) Then If Not _WinAPI_IsWritable($as_CDROM[$i]) Then $s_IsoDrive = $as_CDROM[$i] EndIf Next If $s_IsoDrive = "" Then MsgBox( _ $MB_ICONERROR, _ "Attention: ", _ $s_MarkerFile & " NOT DETECTED!!!" & @CRLF & "This tool is designed for XPE" & @CRLF & "and SE projects only.") GUI_CloseGUI() EndIf Return StringUpper($s_IsoDrive) EndFunc ;==>ISO_GetDriveLetter Func ISO_Mount() ; mount the droppped iso RunWait('cmd /c powershell.exe ' & '"Mount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>ISO_Mount Func ISO_Unmount() ; unmount the dropped iso ; check for mounted drive and unmount if required If $s_MountedDrive <> '' Then RunWait('cmd /c powershell.exe ' & '"Dismount-DiskImage "' & '"' & $CmdLine[1] & '"' & '"' & '"' & ' >nul', @WorkingDir, @SW_HIDE) EndFunc ;==>ISO_Unmount bobomb-test.7z
-
I mean look at the working section of code you have and compare it to what the help page is showing you... The RunWait help a little tough after looking because there are no SW_HIDE @ComSpec or @WorkingDir examples.. I did not notice that before, but the Run help remarks and example shows a little more with an opt flag included.. It takes time, looking around at other peoples code can be helpful too.. https://www.autoitscript.com/autoit3/docs/functions/Run.htm Also you should definately use the SciTE editor located here: https://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe
-
Here is a valid (although ugly) Run line.. Run("cmd /c notepad.exe", @WorkingDir) ; opens notepad using console ; Using @WorkingDir ; Immediately runs the next line in the program or RunWait(@ComSpec & ' /c ' & 'notepad.exe', @WorkingDir, @SW_HIDE) ; opens notepad using cosole with @SW_HIDE flag so you will not see the console window ; Using @WorkingDir ; Waits for the program to close before continuing to the next line They are both functional ways to use run commands
-
Scorpys reacted to a post in a topic: Autoit script doesn't run properly when started from BAT file
-
Yea but you didnt learn what @WorkingDir was... Use that instead of the quoted path. If you are running from the same folder. I highly recommend going back to the help page and looking at the now working section.. It might be hard to understand without context but once u have something working you should be able to see whats going on.. @WorkingDir is a variable you can use not just a (Value) you can enter
-
bobomb reacted to a post in a topic: rant: Windows Defender refuses to execute compiled autoit apps
-
bobomb reacted to a post in a topic: WinNTSetup format helper tool (Is it possible to move the GUI out of this function easily? )
-
bobomb reacted to a post in a topic: WinNTSetup format helper tool (Is it possible to move the GUI out of this function easily? )
-
bobomb reacted to a post in a topic: WinNTSetup format helper tool (Is it possible to move the GUI out of this function easily? )
-
You can also use a tool like 7zSFXConstructor to pack the Au3 and AutoIT3.exe into a single SFX exe.. With that tool you can create a cmd script and during sfx exe creation point to that as the file to execute when the sfx is run.. The tool allows you to pick where you want the file to extract to e.g. %temp% and will self delete the extracted files on process close.. If you do use a cmd script to execute everything inside you can hide the console window completely and use the Start "" ????.cmd to keep the process going until you are finished (for self removal), you can lock running the exe down with a password etc.. An added benefit to the sfx method is that you are executing from removable media, the media can be disconnected after launch while the program is running.. Very simple easy way to package a "compiled" EXE from au3 scripts with AutoIT3.exe without too many headaches... Tool located here: https://github.com/CryptoNickSoft/7z-SFX-Constructor
-
Its probably impossible for us to figure out without the code you are using at the moment.. is this the same as posted before or have you made changes? Is it the above suggested code? Are you using double quotes? '"StringGoesHere"' AutoIT can use a + sign inside a single set of ' ' or " " as a quantifier, and it looks like thats where your address is getting cutoff.. instead of worrying about an escape char you can probably just use single/double quotes.. Of course, without the actual command you are running this is all a guess.. It can also be cmd flags causing the + to be misinterpreted.. etc
-
Depends on how important shares and their share permissions actually are.. it is one way to keep them intact ~
- 10 replies
-
That disk function works perfectly. Very awesome @benners! Below is the updated script. This and the BurnTool in the other thread share functions and basic gui but both do useful things that will make PE users lives easier.. They arent meant to be beautiful but to replace old cmd scripts.. this is much safer than looking at a disk 0 disk 1 disk 2 list in diskpart Also thank you @junkew for helping teach me #NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=PrepareDiskNT.ico #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Comment=Prepare / Format Disks for WinNTSetup #AutoIt3Wrapper_Res_Description=PrepareDiskNT.exe #AutoIt3Wrapper_Res_Fileversion=2.0.0.6 #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ #Tidy_Parameters=/sf #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <StringConstants.au3> Global $c_DiskList = 0 Global $c_MBR_btn = 0 Global $c_GPT_btn = 0 Global $s_BootDrive = "" Global $s_MainDrive = "" Cleanup(False) DirCreate(GetCachePath()) Opt("GUIOnEventMode", 1) GUI_Create() Func Buttons_Disable() GUICtrlSetState($c_MBR_btn, $GUI_DISABLE) GUICtrlSetState($c_GPT_btn, $GUI_DISABLE) EndFunc ;==>Buttons_Disable Func Buttons_Enable() GUICtrlSetState($c_MBR_btn, $GUI_ENABLE) GUICtrlSetState($c_GPT_btn, $GUI_ENABLE) EndFunc ;==>Buttons_Enable Func Cleanup($b_Exit = True) If FileExists(GetCachePath()) Then DirRemove(GetCachePath(), $DIR_REMOVE) If $b_Exit Then Exit EndFunc ;==>Cleanup Func DiskList_GetDrives() Local Const $WBEMFLAGRETURNIMMEDIATELY = 0x10 Local Enum _ $Unknown, _ $NoRootDirectory, _ $RemovableDisk, _ $LocalDisk, _ $NetworkDrive, _ $CompactDisk, _ $RAMDisk Local $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") If IsObj($o_WMIService) Then Local $s_Query = "SELECT * FROM Win32_DiskDrive" Local $o_DiskDrives = $o_WMIService.ExecQuery($s_Query, "WQL", $WBEMFLAGRETURNIMMEDIATELY) If IsObj($o_DiskDrives) Then Local $o_Partitions = 0 Local $o_LogicalDisks = 0 For $o_DiskDrive In $o_DiskDrives $h_Parent = GUICtrlCreateTreeViewItem("Disk " & $o_DiskDrive.Index & " [" & $o_DiskDrive.Model & "]", $c_DiskList) GUICtrlSetOnEvent(-1, 'Buttons_Enable') _GUICtrlTreeView_SetIcon($c_DiskList, $h_Parent, "shell32.dll", 15) $s_Query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $o_DiskDrive.DeviceId & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" $o_Partitions = $o_WMIService.ExecQuery($s_Query) If IsObj($o_Partitions) Then For $o_Partition In $o_Partitions $s_Query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $o_Partition.DeviceId & "'} WHERE AssocClass = Win32_LogicalDiskToPartition" $o_LogicalDisks = $o_WMIService.ExecQuery($s_Query) For $o_LogicalDisk In $o_LogicalDisks If $o_LogicalDisk.drivetype = $RemovableDisk Or $o_LogicalDisk.drivetype = $LocalDisk Then GUICtrlCreateTreeViewItem('(' & $o_LogicalDisk.DeviceId & '\) ' & $o_LogicalDisk.Volumename, $h_Parent) GUICtrlSetOnEvent(-1, 'Buttons_Disable') _GUICtrlTreeView_SetIcon($c_DiskList, -1, "shell32.dll", 7) EndIf Next Next Else ; add error info here EndIf Next Else ; add error info here EndIf Else ; add error info here EndIf EndFunc ;==>DiskList_GetDrives Func DiskList_Load() _GUICtrlTreeView_BeginUpdate($c_DiskList) _GUICtrlTreeView_DeleteAll($c_DiskList) DiskList_GetDrives() If _GUICtrlTreeView_GetCount($c_DiskList) > 2 Then _GUICtrlTreeView_Sort($c_DiskList) _GUICtrlTreeView_Expand($c_DiskList) _GUICtrlTreeView_EndUpdate($c_DiskList) Buttons_Disable() EndFunc ;==>DiskList_Load Func DiskPart_CreateScriptFile($s_FileName, $s_Message) Local $h_File = FileOpen($s_FileName, 2) FileWrite($h_File, $s_Message) FileClose($h_File) EndFunc ;==>DiskPart_CreateScriptFile Func GetCachePath() Local Static $s_CachePath = IniRead(@WorkingDir & '\PrepareDiskNT.ini', "Settings", "CachePath", @WorkingDir & '\cache') & '\' Return $s_CachePath EndFunc ;==>GetCachePath Func GetDriveLetters() Local $s_AllDriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ" Local $as_Drives = DriveGetDrive($DT_ALL) If @error Then ; An error occurred when retrieving the drives. MsgBox( _ BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), _ "Drive Letters", _ "Unable to retrieve available drive letters! Exiting Program...") Cleanup() Else Local $s_DriveLetter For $i = 1 To $as_Drives[0] $s_DriveLetter = StringLeft(StringUpper($as_Drives[$i]), 1) $s_AllDriveLetters = StringReplace($s_AllDriveLetters, $s_DriveLetter, "") Next EndIf Local $as_AvailDriveLetters = StringSplit($s_AllDriveLetters, "") $s_BootDrive = $as_AvailDriveLetters[1] ; Get first available letter $s_MainDrive = $as_AvailDriveLetters[2] ; Get second available letter EndFunc ;==>GetDriveLetters Func GPT_Format() GUISetState(@SW_HIDE) Local $as_DiskPart[10][2] = [ _ [9, 0], _ ["Cleaning Drive", 'clean.dat'], _ ["Cleaning Drive", 'scrub.dat'], _ ["Cleaning Drive", 'clean.dat'], _ ["Resetting Disk Attributes", 'attrib.dat'], _ ["Converting Layout to GPT", 'convert.dat'], _ ["Creating System Partition", 'formatsystem.dat'], _ ["Creating MSR Partition", 'createmsr.dat'], _ ["Creating Windows Partition", 'formatmain.dat'], _ ["Creating WinRE Partition", 'formatwinre.dat'] _ ] ProgressOn("Formatting GPT (UEFI)...", "Preparing Disk: ", "0%") For $i = 1 To $as_DiskPart[0][0] ProgressSet($i * 11 & "%", $as_DiskPart[$i][0]) RunWait(@ComSpec & ' /c diskpart /s ' & '"' & GetCachePath() & $as_DiskPart[$i][1] & '"', @WorkingDir, @SW_HIDE) Sleep(750) Next ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>GPT_Format Func GPT_Pressed() Local $s_DiskNumber = StringRegExp(GUICtrlRead($c_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH) If $s_DiskNumber = "" Then MsgBox( _ $MB_ICONERROR, _ ; it is possible to bug the GUI and make the buttons appear by pressing + or - on tree then refresh "Attention: ", _ "No disk is selected!") Buttons_Disable() Else $s_DiskNumber = StringRegExp(GUICtrlRead($c_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0] If @error Then MsgBox( _ $MB_ICONERROR, _ "Attention: ", _ "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 GPT_Prepare($s_DiskNumber) GPT_Format() GPT_WriteIni() MsgBox( _ $MB_ICONINFORMATION, _ "Redirecting... ", _ " - WinNTSetup will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $s_BootDrive & @CRLF & 'Install Drive: ' & $s_MainDrive) WinNTSetup_Launch() Cleanup() EndIf EndIf EndIf EndFunc ;==>GPT_Pressed Func GPT_WriteIni() Local $s_IniFile = WinNTSetup_GetPath() & "WinNTSetup.ini" IniWrite($s_IniFile, "WinNT6", "BootDest", $s_BootDrive & ":") IniWrite($s_IniFile, "WinNT6", "TempDest", $s_MainDrive & ":") IniWrite($s_IniFile, "WinNT5", "BootDest", $s_BootDrive & ":") IniWrite($s_IniFile, "WinNT5", "TempDest", $s_MainDrive & ":") EndFunc ;==>GPT_WriteIni Func GPT_Prepare($s_DiskNumber) GetDriveLetters() DiskPart_CreateScriptFile(GetCachePath() & 'clean.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'clean' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'scrub.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=GPTscrubber' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'attrib.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'convert.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'convert gpt' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'formatsystem.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'cre par efi size=100' & @CRLF & 'format quick fs=fat32 label=System' & @CRLF & 'assign letter=' & $s_BootDrive & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'createmsr.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'cre par msr size=16' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'formatmain.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'cre par pri' & @CRLF & 'shrink minimum=450' & @CRLF & 'format quick fs=ntfs label=Windows' & @CRLF & 'assign letter=' & $s_MainDrive & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'formatwinre.dat', 'Sel Dis ' & $s_DiskNumber & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=ntfs label=WinRE' & @CRLF & 'set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac' & @CRLF & 'Exit') EndFunc ;==>GPT_Prepare Func GUI_Create() GUICreate('Prep/Format Disk v2.0', 300, 289) GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Close") GUISetIcon(@WorkingDir & '\PrepareDiskNT.ico', 1) GUISetBkColor(0x898989) GUICtrlCreateLabel('1: Select a disk to prepare for WinNTSetup', 20, 10, 280) $c_DiskList = GUICtrlCreateTreeView(10, 30, 280, 150) DiskList_Load() GUICtrlCreateButton('Refresh List', 110, 185, 80, 25) GUICtrlSetOnEvent(-1, "DiskList_Load") GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateLabel('2: Select your desired layout...', 20, 214, 280, 30) $c_MBR_btn = GUICtrlCreateButton('MBR (BIOS) Boot', 20, 234, 120, 40) GUICtrlSetOnEvent(-1, "MBR_Pressed") GUICtrlSetState(-1, $GUI_DISABLE) $c_GPT_btn = GUICtrlCreateButton('GPT (UEFI) Boot', 160, 234, 120, 40) GUICtrlSetOnEvent(-1, "GPT_Pressed") GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() ; Just idle around While 1 Sleep(10) WEnd EndFunc ;==>GUI_Create Func GUI_Close() Cleanup() EndFunc ;==>GUI_Close Func MBR_Format() GUISetState(@SW_HIDE) Local $as_DiskPart[7][2] = [ _ [6, 0], _ ["Cleaning Drive", 'clean.dat'], _ ["Cleaning Drive", 'scrub.dat'], _ ["Cleaning Drive", 'clean.dat'], _ ["Resetting Disk Attributes", 'attrib.dat'], _ ["Converting Layout to MBR", 'convert.dat'], _ ["Creating Windows Partition", 'formatmain.dat'] _ ] ProgressOn("Formatting MBR (BIOS)...", "Preparing Disk: ", "0%") For $i = 1 To $as_DiskPart[0][0] ProgressSet($i * 17 & "%", $as_DiskPart[$i][0]) RunWait(@ComSpec & ' /c diskpart /s ' & '"' & GetCachePath() & $as_DiskPart[$i][1] & '"', @WorkingDir, @SW_HIDE) Sleep(750) Next ProgressSet(100, "Finished", "Format Completed") Sleep(1500) ProgressOff() GUISetState() EndFunc ;==>MBR_Format Func MBR_Prepare($s_Drive) GetDriveLetters() DiskPart_CreateScriptFile(GetCachePath() & 'clean.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'clean' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'scrub.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=MBRscrubber' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'attrib.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'attribute disk clear readonly' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'convert.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'convert mbr' & @CRLF & 'Exit') DiskPart_CreateScriptFile(GetCachePath() & 'formatmain.dat', 'Sel Dis ' & $s_Drive & @CRLF & 'cre par pri' & @CRLF & 'format quick fs=NTFS label=Windows' & @CRLF & 'Active' & @CRLF & 'Assign letter=' & $s_BootDrive & @CRLF & 'Exit') EndFunc ;==>MBR_Prepare Func MBR_Pressed() Local $s_DiskNumber = StringRegExp(GUICtrlRead($c_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH) If $s_DiskNumber = "" Then MsgBox( _ $MB_ICONERROR, _ ; it is possible to bug the GUI and make the buttons appear by pressing + or - on tree then refresh "Attention: ", _ "No disk is selected!") Buttons_Disable() Else $s_DiskNumber = StringRegExp(GUICtrlRead($c_DiskList, $GUI_READ_EXTENDED), '(?<=Disk\s)[0-9]+', $STR_REGEXPARRAYMATCH)[0] If @error Then MsgBox( _ $MB_ICONERROR, _ "Attention: ", _ "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 MBR_Prepare($s_DiskNumber) MBR_Format() MBR_WriteIni() MsgBox($MB_ICONINFORMATION, "Redirecting... ", " - WinNTSetup will now open - " & @CRLF & @CRLF & 'Boot Drive: ' & $s_BootDrive & @CRLF & 'Install Drive: ' & $s_BootDrive) WinNTSetup_Launch() Cleanup() EndIf EndIf EndIf EndFunc ;==>MBR_Pressed Func MBR_WriteIni() Local $s_IniFile = WinNTSetup_GetPath() & "WinNTSetup.ini" IniWrite($s_IniFile, "WinNT6", "BootDest", $s_BootDrive & ":") IniWrite($s_IniFile, "WinNT6", "TempDest", $s_BootDrive & ":") IniWrite($s_IniFile, "WinNT5", "BootDest", $s_BootDrive & ":") IniWrite($s_IniFile, "WinNT5", "TempDest", $s_BootDrive & ":") EndFunc ;==>MBR_WriteIni Func WinNTSetup_GetPath() Local Static $s_WinNTSetupPath = IniRead(@WorkingDir & '\PrepareDiskNT.ini', "Settings", "WinNTSetupPath", @WorkingDir) & '\' If $s_WinNTSetupPath = '\' Then $s_WinNTSetupPath = '' Return $s_WinNTSetupPath EndFunc ;==>WinNTSetup_GetPath Func WinNTSetup_Launch() Run(@ComSpec & ' /c ""' & WinNTSetup_GetPath() & 'WinNTSetup_x64.exe""', @WorkingDir, @SW_HIDE) EndFunc ;==>WinNTSetup_Launch PrepareDiskNT.ini (PrepareDiskNT.exe can be used in the same folder as WinNTSetup.exe, If PrepareDiskNT.ini exists, it can be used to set the relative path to WinNTSetup.exe) [Settings] WinNTSetupPath=