📄 winsetupfromusb_0-1-1.au3
字号:
$sl = $SourceList[$i][1]
$dest = $SourceList[$i][2]
;_ArrayDisplay($src)
If _CopyDirWithProgress($src, $dest, $sl, $SourceList[0][1]) = -2 Then ExitLoop 2
Next
$dif = TimerDiff($begin) / 1000
Logging("Copying completed." & " Took: " & $dif & " seconds")
_GUICtrlStatusBar_SetText($hStatus,"Copy completed", 2)
EndIf ;preparing source files and folders
;taking care of unattended section and presetup.cmd/$OEM$
;ensuring presetup is launched
If FileExists($TargetDrive & "\$WIN_NT$.~BT\winnt.sif") And $WinSource <> "" Then
$txtsetupsif = $TargetDrive & "\txtsetup.sif"
Logging("Fixing unattended section in winnt.sif")
_GUICtrlStatusBar_SetText($hStatus,"Fixing unattended section in winnt.sif", 2)
If $AMD64 = 1 Then
$file = $TargetDrive & "\$WIN_NT$.~LS\AMD64\presetup.cmd"
ElseIf $AMD64 = 0 Then
$file = $TargetDrive & "\$WIN_NT$.~LS\I386\presetup.cmd"
EndIf
If Not FileExists($file) Then
If $AMD64 = 1 Then
IniWrite($txtsetupsif, "SourceDisksFiles", "presetup.cmd", "1,,,,,,,82,0,0")
IniWrite($txtsetupsif, "SourceDisksFiles", "setupORG.exe", "1,,,,,,,82,0,0")
ElseIf $AMD64 = 0 Then
IniWrite($txtsetupsif, "SourceDisksFiles", "presetup.cmd", "1,,,,,,,2,0,0")
IniWrite($txtsetupsif, "SourceDisksFiles", "setupORG.exe", "1,,,,,,,2,0,0")
EndIf
FileWriteLine($file, "SET TAGFILE=\$WIN_NT$.~LS" & @CRLF & 'FOR %%h IN (U D M N O P Q R S T V W X Y) DO IF EXIST "%%h:%TAGFILE%" SET CDDRIVE=%%h:' & @CRLF)
FileWriteLine($file, 'if "%CDDRIVE%" == "" (' & @CRLF & 'FOR %%h IN (C E F G H I J K L) DO IF EXIST "%%h:%TAGFILE%" SET CDDRIVE=%%h:' _
& @CRLF & ")")
EndIf
FileSetAttrib($file, "-RSH")
If $AMD64 = 0 Then
$filespath = $TargetDrive & "\$WIN_NT$.~LS\I386\"
ElseIf $AMD64 = 1 Then
$filespath = $TargetDrive & "\$WIN_NT$.~LS\AMD64\"
EndIf
$presetup = FileRead($file)
$presetup = StringReplace($presetup, "EXIT", "")
$presetup &= @CRLF & "REM ===========Added by WinSetupFromUSB============" & @CRLF
If Not FileExists($filespath & "setupORG.exe") Then
Logging("setupORG.exe not found, replacing the original file")
RunWait("expand " & $filespath & "setup.ex_ " & $filespath & "setupORG.exe", "", @SW_HIDE)
If Not FileCopy(@ScriptDir & "\files\winsetup\setup.ex_", $filespath, 1) Then
FileSetAttrib($filespath & "setup.ex_", "-RSH")
If Not FileCopy(@ScriptDir & "\files\winsetup\setup.ex_", $filespath, 1) Then
FileDelete($filespath & "setup.ex_")
If Not FileCopy(@ScriptDir & "\files\winsetup\setup.ex_", $filespath, 1) Then
MsgBox(48, "Fatal error", "Could not replace original Setup.exe, this is a fatal error." _
& "Will have to abort, please report at msfn.org forum")
Logging("Could not replace original Setup.exe, aborting...")
Quit()
EndIf
EndIf
EndIf
EndIf
$DriversPath = IniRead($TargetDrive & "\$WIN_NT$.~BT\winnt.sif", "Unattended", "OemPnPDriversPath", "")
If Not @error And $DriversPath <> "" Then
Logging("Adding spdrvscn32.exe to presetup.cmd")
$DriversPath = StringReplace($DriversPath, '"', '')
$DriversPath = "%systemdrive%\" & $DriversPath
$DriversPath = '"' & StringReplace($DriversPath, ";", ";%systemdrive%\") & '"'
If $AMD64 = 0 Then
FileCopy(@ScriptDir & "\files\winsetup\spdrvscn32.exe", $TargetDrive & "\$WIN_NT$.~LS\I386\", 1)
$presetup &= "%CDDRIVE%\$WIN_NT$.~LS\I386\spdrvscn32.exe /d " & $DriversPath & " /s /q /i" & @CRLF
ElseIf $AMD64 = 1 Then
FileCopy(@ScriptDir & "\files\winsetup\spdrvscn64.exe", $TargetDrive & "\$WIN_NT$.~LS\I386\", 1)
$presetup &= "%CDDRIVE%\$WIN_NT$.~LS\I386\spdrvscn64.exe /d " & $DriversPath & " /s /q /i" & @CRLF
EndIf
EndIf
$presetup &= "IF EXIST %systemroot%\system32\setupold.exe DEL /F %systemroot%\system32\setupold.exe" & @CRLF
$OEMPreinstall = IniRead($TargetDrive & "\$WIN_NT$.~BT\winnt.sif", "Unattended", "OemPreinstall", "")
If Not @error Then
If $OEMPreinstall = "1" Or $OEMPreinstall = '"1"' Or $OEMPreinstall = "yes" Or $OEMPreinstall = '"yes"' Then
Logging("OEMPreinstall found, editing presetup.cmd")
$presetup &= "IF EXIST %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$1\nul xcopy %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$1\*.* %systemdrive%\ /i /k /e /r /y /h" & @CRLF
$presetup &= "IF EXIST %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$$\nul xcopy %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$$\*.* %systemroot%\ /i /k /e /r /y /h" & @CRLF
$presetup &= 'IF EXIST %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$Progs\nul xcopy %CDDRIVE%\$WIN_NT$.~LS\$OEM$\$Progs\*.* "%systemdrive%\Program Files\" /i /k /e /r /y /h' & @CRLF
EndIf
EndIf
$unattend = IniReadSection($TargetDrive & "\$WIN_NT$.~BT\winnt.sif", "Unattended")
If Not @error Then
$unatout = @CRLF & "[Unattended]" & @CRLF
For $i = 1 To $unattend[0][0]
$unatout &= $unattend[$i][0] & "=" & $unattend[$i][1] & @CRLF
Next
IniDelete($TargetDrive & "\$WIN_NT$.~BT\winnt.sif", "Unattended")
IniWrite($txtsetupsif, "SourceDisksFiles", "tempunat.inf", "1,,,,,,,2,0,0")
$presetup &= "type %systemroot%\system32\tempunat.inf >> %systemroot%\system32\$winnt$.inf" & @CRLF
If $AMD64 = 1 Then
FileWrite($TargetDrive & "\$WIN_NT$.~LS\AMD64\tempunat.inf", $unatout)
Else
FileWrite($TargetDrive & "\$WIN_NT$.~LS\I386\tempunat.inf", $unatout)
EndIf
EndIf
;FileCopy(@ScriptDir & "\files\winsetup\fedit.exe", $TargetDrive & "\$WIN_NT$.~LS\I386\", 1)
;$presetup &= "IF EXIST %systemroot%\system32\$WINNT$.PNF DEL /F %systemroot%\system32\$WINNT$.PNF" & @CRLF
;$presetup &= "attrib -r -s -h $SystemRoot$\system32\$winnt$.inf" & @CRLF
;$presetup &= "%CDDRIVE%\$WIN_NT$.~LS\I386\fedit.exe -f %systemroot%\system32\$winnt$.inf -rem -l:o MsDosInitiated -s Data" & @CRLF
;$presetup &= '%CDDRIVE%\$WIN_NT$.~LS\I386\fedit.exe -f %systemroot%\system32\$winnt$.inf -add -create -l "MsDosInitiated = 0" -s Data' & @CRLF
$presetup &= "IF EXIST c:\boot.003 DEL /F c:\boot.003" & @CRLF
;$presetup &= "%systemroot%\system32\binifix4.cmd C:" & @CRLF
$presetup &= "REM ====================END=======================" & @CRLF
$presetup &= "EXIT" & @CRLF
$file = FileOpen($file, 10)
FileWrite($file, $presetup)
FileClose($file)
EndIf
;hexedit \minint\setupldr.bin if PE and WinSetup exist and winnt.sif
If FileExists($TargetDrive & "\txtsetup.sif") And FileExists($TargetDrive & "\minint\") And GUICtrlRead($BootOnlyCheck) = $GUI_UNCHECKED _
And FileExists($TargetDrive & "\minint\setupldr.bin.bak") = 0 Then
Logging("Patching \minint\setupldr.bin")
_GUICtrlStatusBar_SetText($hStatus,"Patching minint\setupldr.bin", 2)
HexReplace($TargetDrive & "\minint\setupldr.bin", "txtsetup.sif", "notsetup.sif", 1, 16)
Logging("Fixing checksum check in \minint\setupldr.bin")
HexReplace($TargetDrive & "\minint\setupldr.bin", "46DA7403E908", "46DAEB1AE908", 1, 16, 1)
EndIf
If FileExists($TargetDrive & "\minint\") And GUICtrlRead($AddPECheck) = $GUI_CHECKED Then
Logging("Fixing \minint\winnt.sif")
_GUICtrlStatusBar_SetText($hStatus,"Fixing minint\winnt.sif", 2)
$ini = $TargetDrive & "\minint\WINNT.SIF"
$data = 'msdosinitiated="1"' & @LF & 'floppyless="1"' & @LF & 'AutoPartition="0"' & @LF & 'UseSignatures="no"' & @LF _
& @LF & 'winntupgrade="no"' & @LF & 'win9xupgrade="no"' & @LF
IniWriteSection($ini, "data", $data)
If Not FileExists($TargetDrive & "\ntdetect.com") Then FileCopy($TargetDrive & "\minint\ntdetect.com", $TargetDrive)
EndIf
If FileExists($TargetDrive & "\cmdcons\") And GUICtrlRead($AddPECheck) = $GUI_CHECKED Then
Logging("Fixing \cmdcons\winnt.sif")
_GUICtrlStatusBar_SetText($hStatus,"Fixing cmdcons\winnt.sif", 2)
$ini = $TargetDrive & "\cmdcons\WINNT.SIF"
$data = 'msdosinitiated="1"' & @LF & 'floppyless="1"' & @LF & 'AutoPartition="0"' & @LF & 'UseSignatures="no"' & @LF & 'InstallDir="\WINDOWS"' _
& @LF & 'winntupgrade="no"' & @LF & 'win9xupgrade="no"' & @LF & 'EulaComplete="1"' & @LF
IniWriteSection($ini, "data", $data)
If Not FileExists($TargetDrive & "\ntdetect.com") Then FileCopy($TargetDrive & "\minint\ntdetect.com", $TargetDrive)
EndIf
If $instsyslin = 1 Then
InstallSysLinux()
EndIf
If FileExists($TargetDrive & "\boot.ini") Then
Logging("Removing duplicate entries in boot.ini")
_GUICtrlStatusBar_SetText($hStatus,"Removing duplicate entries in boot.ini", 2)
$file = $TargetDrive & "\boot.ini"
_FileReadToArray($file, $aArray)
If Not @error Then
DeDupe($aArray, 1)
$file = FileOpen($TargetDrive & "\boot.ini", 2)
_ArrayDelete( $aArray, 0)
_FileWriteFromArray($file, $aArray)
FileClose($file)
EndIf
EndIf
_GUICtrlStatusBar_SetText($hStatus,"Flushing data to disks", 2)
RunWait(@ComSpec & " /c sync.exe " & StringLeft($TargetDrive, 1) & " " & StringLeft($TargetActive, 1), @ScriptDir & "\files\tools\", @SW_HIDE)
If GUICtrlRead($qemu) = $GUI_CHECKED And $TargetDrive <> "" Then
Logging("Launching QEMU")
_GUICtrlStatusBar_SetText($hStatus,"Launching QEMU...", 2)
Sleep(1500)
RunWait('"' & @ScriptDir & '\files\qemu\qemu-system-x86_64.exe' & '"' & ' -L ' & '"' & @ScriptDir & '\files\qemu' _
& '"' & ' -boot c -m 256 -hda //./PhysicalDrive' & $USBdrives[$USBdrives[0][1]][2],"",@SW_HIDE)
Sleep(1000)
EndIf
_GUICtrlStatusBar_SetText($hStatus,"Done.", 2)
If $WinSource <> "" Then
MsgBox(48, "This is important!", "Keep the USB disk plugged in AND start from USB 3 times:" & @CRLF & @CRLF _
& "1. Text mode part of setup" & @CRLF & "2. GUI mode part of setup" & @CRLF & "3. Start Windows for first time.")
Else
MsgBox(0,"Done", "Done")
EndIf
ExitLoop
WEnd
GUICtrlSetData($Go, "GO")
DisableMenus(0)
$WinSource = ""
$TempWinSource = ""
GUICtrlSetData($Source, "")
GUICtrlSetState($BootINIAddCheck, $GUI_UNCHECKED)
GUICtrlSetState($AddPECheck, $GUI_UNCHECKED)
GUICtrlSetState($AddVistaCheck, $GUI_UNCHECKED)
GUICtrlSetState($AddGPartedCheck, $GUI_UNCHECKED)
GUICtrlSetState($AddSysLinuxCheck, $GUI_UNCHECKED)
GUICtrlSetState($qemu, $GUI_UNCHECKED)
EnableInputBox()
GUICtrlSetData($ProgressAll, 0)
PopulateUSBComboBox()
EndFunc ;==>Main()
;===================================================================================================
Func PopulateUSBComboBox()
Local $i, $cs = 0
If _GUICtrlComboBox_GetCurSel($ComboBoxTarget) = -1 Then
_GUICtrlComboBox_ResetContent($ComboBoxTarget)
Else
$cs = _GUICtrlComboBox_GetCurSel($ComboBoxTarget)
_GUICtrlComboBox_ResetContent($ComboBoxTarget)
EndIf
Logging("Getting USB drives information")
_GUICtrlStatusBar_SetText($hStatus,"Getting USB drives information", 2)
$USBdrives = _GetUSBDrivesInfo()
;array is in format--> DriveLetter | Name | Disk# | Part# | TotalSpace | FreeSpace | DriveType | FileSystem | Bootable(-1) or Not ( )
For $i = 1 To $USBdrives[0][0]
GUICtrlSetData($ComboBoxTarget,$USBdrives[$i][0] & "\ " & $USBdrives[$i][1] & _
"(" & $USBdrives[$i][4] & "MB Total) " & "(" & $USBdrives[$i][7] & ") " & "(" & $USBdrives[$i][5] & "MB Free)")
Next
_GUICtrlComboBox_SetCurSel($ComboBoxTarget, $cs) ;debug
;_ArrayDisplay ($USBdrives)
If $USBdrives[0][0] > 0 Then
GetComboUSBSelection()
Else
_GUICtrlComboBox_ResetContent($ComboBoxTarget)
GUICtrlSetData($ComboBoxTarget,"No USB Disks detected or not properly formatted","No USB Disks detected or not properly formatted")
Logging ("No USB Disks detected or not properly formatted")
EndIf
CheckSize()
CheckGo()
EndFunc ;==>_PopulateUSBComboBox()
;===================================================================================================
Func _GetUSBDrivesInfo()
Local $USBDlettersInfo[1][9], $NrOfFoundUSB = 0, $dp, $HasBootPart
Local $strComputer = ".", $objDrive, $strDeviceID, $colPartitions, $objPartition, $colLogicalDisks, $objLogicalDisk
Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
Local $colDiskDrives = $objWMIService.ExecQuery("Select * from Win32_DiskDrive Where (InterfaceType like " & chr(34) & "%USB%" & chr(34) & ")")
For $objDrive In $colDiskDrives
$HasBootPart = 0
Logging( "Found USB Physical Disk: " & $objDrive.Caption & " -- " & $objDrive.DeviceID)
$strDeviceID = StringReplace($objDrive.DeviceID, "\", "\\")
Local $colPartitions = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $strDeviceID & """}" _
& "WHERE AssocClass = Win32_DiskDriveToDiskPartition")
;check if this disk has bootable partitions
For $objPartition In $colPartitions
If $objPartition.Bootable = -1 Then
$HasBootPart = 1
ExitLoop
EndIf
Next
If $HasBootPart = 1 Then
For $objPartition In $colPartitions
Logging( "Found USB Disk Partition: " & $objPartition.DeviceID)
$colLogicalDisks = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $objPartition.DeviceID & """}" _
& "WHERE AssocClass = Win32_LogicalDiskToPartition" )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -