#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <GuiListView.au3>
#include <GuiListBox.au3>
#include <string.au3>
#include <Constants.au3>
#include <WinAPI.au3>
Global $PageNum = 1, $LevelForm, $Levelgroup, $LevelView, $SelectMoreButton, $SelectNextButton, $SelectCancelButton, $Levelgroup2, $LevelLabel
Global $title = " Win7/8系统安装工具", $WinSize
$varhd = "C:"
#region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("WINDOWS7/8安装工具 制作:NDYZX", 408, 149)
$Label1 = GUICtrlCreateLabel("选择安装文件", 8, 8, 79, 17)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008080)
$Input1 = GUICtrlCreateInput("C:", 88, 8, 249, 21)
$Label2 = GUICtrlCreateLabel("选择映像版本", 8, 40, 79, 17)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008080)
$Combo2 = GUICtrlCreateCombo("1", 88, 40, 313, 25)
$Label3 = GUICtrlCreateLabel("选择安装分区", 8, 72, 79, 17)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008080)
$Combo3 = GUICtrlCreateCombo("C:", 88, 72, 313, 25)
$Label4 = GUICtrlCreateLabel("选择启动分区", 8, 104, 79, 17)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008080)
$Combo4 = GUICtrlCreateCombo($varhd, 88, 104, 81, 25)
$Button1 = GUICtrlCreateButton("浏览", 344, 8, 60, 21)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008000)
$Button2 = GUICtrlCreateButton("开始安装", 328, 104, 75, 21)
GUICtrlSetFont(-1, 9, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x008000)
$Label5 = GUICtrlCreateLabel("注意:点击安装后,会格式化安装分区,请保存好资料。", 24, 128, 376, 20)
GUICtrlSetFont(-1, 10, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF0000)
$ProButton2 = GUICtrlCreateEdit("", 1, 100, 407, 49)
GUICtrlSetFont(-1, 8, 500, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetState($ProButton2, $gui_hide)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;-----------------------以下为选择引导区-------------------------------------------
Local $getlist
$var = DriveGetDrive("FIXED")
Global $FileNum
If Not @error Then
For $i = 1 To $var[0]
$varhd = GUICtrlSetData($Combo4, StringUpper($var[$i]))
Next
EndIf
;注,引导区的盘符为$getlist后面 要用到
;-----------------------以下为选择安装分区-------------------------------------------
$HDr = DriveGetDrive("FIXED")
Dim $sizeAll[$HDr[0] + 1]
Dim $sizeFre[$HDr[0] + 1]
Dim $SYS[$HDr[0] + 1]
Dim $xs[$HDr[0] + 1]
For $i = 1 To $HDr[0]
$sizeAll[$i] = Int(DriveSpaceTotal($HDr[$i] & ""))
$sizeFre[$i] = Int(DriveSpaceFree($HDr[$i] & ""))
$SYS[$i] = DriveGetFileSystem($HDr[$i] & "")
Next
$xs2 = ""
For $i = 1 To $HDr[0]
$xs[$i] = StringUpper($HDr[$i]) & "盘,格式:" & $SYS[$i] & ",总空间:" & $sizeAll[$i] & "M,剩余空间:" & $sizeFre[$i] & "M。"
If $i > 1 Then
$xs2 = $xs2 & $xs[$i] & "|"
EndIf
Next
GUICtrlSetState($Combo3, $gui_hide)
$fq3 = GUICtrlCreateCombo($xs[1], 88, 72, 313, 25)
GUICtrlSetData(-1, $xs2, $xs[1])
While 1
$nmsg = GUIGetMsg()
Switch $nmsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;本句柄为点击浏览并找到WIM文件后显示WIM里WIM8的版本
Global $Image[20], $LevelInfo[20], $LevelDiscrip[20], $MINOR[20]
GUICtrlSetData($Combo2, "")
$wim = FileOpenDialog("请选择指定Windows安装文件的Wim映像", "", "Windows映像文件(*.wim)|所有文件(*.*)", 1 + 2, "install.wim")
GUICtrlSetData($Input1, $wim)
GUICtrlSetData($Combo2, "")
FileDelete(EnvGet("Temp") & '\wiminfo.txt')
_RunDos('"' & @TempDir & '\imagex.exe"' & ' /info "' & $wim & '" >"' & @TempDir & '\wiminfo.txt"')
$txt = FileRead(EnvGet("Temp") & "\wiminfo.txt")
ClipPut($txt)
Local $txt = ClipGet()
$svar = StringRegExp($txt, '<IMAGE INDEX="(\V|">)', 3)
$var = StringRegExp($txt, '<DISPLAYNAME>(\V+)</DISPLAYNAME>', 3)
If @error Then
MsgBox(4096, "", "错误, 读取列表文件失败.")
Else
For $i = 0 To UBound($var) - 1
For $i = 0 To UBound($svar) - 1
GUICtrlSetData($Combo2, $svar[$i] & "." & $var[$i])
Next
Next
_GUICtrlComboBox_SetEditText($Combo2, '正在获取信息,稍后从下拉列表中选择。')
ClipPut ( "" )
EndIf
Case $Button2;
GUICtrlSetState($Label1, $GUI_HIDE)
GUICtrlSetState($Input1, $GUI_HIDE)
GUICtrlSetState($Button1, $GUI_HIDE)
GUICtrlSetState($Label2, $GUI_HIDE)
GUICtrlSetState($Combo2, $GUI_HIDE)
GUICtrlSetState($Label3, $GUI_HIDE)
GUICtrlSetState($Combo3, $GUI_HIDE)
GUICtrlSetState($Label4, $GUI_HIDE)
GUICtrlSetState($Button2, $GUI_HIDE)
GUICtrlSetState($Label3, $GUI_HIDE)
GUICtrlSetState($Combo4, $GUI_HIDE)
$getlist = GUICtrlRead($Combo4);为引导盘变量
$q = GUICtrlRead($fq3) ;本名为读取框中文本这里作为安装按钮的示例,正式出来要换掉
$W = StringLeft($q, 2) ;为安装分区变量。截取 文本前两位为安装位置
$x = GUICtrlRead($Input1) ;为WIM文件路径
$y = GUICtrlRead($Combo2)
Local $T = StringRegExpReplace(StringRegExpReplace($y, '^(.{1,3}).*', '$1'), '\D', '');为wim文件映像编号,正则提取字符串的前三位数字。
_Rundism()
Sleep(3000)
ExitLoop
EndSwitch
WEnd
Run(@ComSpec & " /c " & 'pecmd shut r', "", @SW_HIDE)
Func _Rundism()
$Label1 = GUICtrlCreateLabel("正在安装", 8, 8, 79, 17)
$ProButton2 = GUICtrlCreateEdit("", 1, 22, 407, 149,BitOR(0x00200000,0x0800))
GUISetState(@SW_SHOW)
GUICtrlSetData($ProButton2,"安装进程...",' ')
;$foo = Run("@TempDir & '\imagex.exe' & ' /apply ' & $x & ' ' & $T & ' ' & $W & '\'", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$foo = Run('qll.bat',"", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
$linea = StdoutRead($foo)
If @error Then ExitLoop
Dim $ProgressA,$ProgressB,$ImageXProgress
If StringStripWS($linea,8)<>"" Then
GUICtrlSetData($ProButton2,@CRLF&$linea,' ')
If StringInStr(StringStripCR($linea),"Applying progress") Then
$ProgressA=StringSplit(StringStripCR($linea),"]")
$ProgressB=StringSplit($ProgressA[1],"[")
$ImageXProgress=StringStripCR(StringStripWS($ProgressB[2],8))
EndIf
EndIf
WEnd
EndFunc ;==>_Rundism
Func _RunDos($sCommand)
Return RunWait(@ComSpec & " /C """ & $sCommand & """", "", @SW_HIDE)
EndFunc ;==>_RunDos