44
44
au3> Dim $avDriveMa pAdd[7] $avDriveMapAdd[0] = "Unknown Error" $avDriveMapAdd[1] = "Undefined / Other error" $avDriveMapAdd[2] = "Access to the remote share was denied" $avD riveMapAdd[3] = "The device is already assigned" $avDriveMapAdd[4] = "Invali d device name" $avDriveMapAdd[5] = "Invalid remote share" $avDriveMapAdd[6] = "Invalid password" Dim $avPing [5] $avPing[0] = "Unknown Error" $avPing[1] = " Host is offline" $avPing[2] = "Host is unreachable" $avPing[3] = "Bad destinatio n" $avPing[4] = "Other errors" ; Global Settings ; Dim $gCaptureSource Dim $gCap tureDestination Dim $gCaptureCompression Dim $gCaptureFlags Dim $gCaptureConfig Dim $gCaptureBoot Dim $gCaptureCheck Dim $gCaptureName Dim $gCaptureDescription Dim $gApplySource Dim $gApplyDestination Dim $gApplyVerify Dim $gApplyName Dim $ imageinfo Dim $gMapLetter Dim $gMapUser Dim $gMapPassword Dim $gMapShare Dim $sI ni = @ScriptDir & "\gimagex.ini" Dim $res ; ; Create the main GUI ; GUICreate("G ImageX - ImageX GUI Wrapper", 640, 380, -1, -1 ) $hTab = GUICtrlCreateTab(10, 10 , 620, 355) $BaseX = 20 $BaseY = 35 ; Drive Map Tab $hTab_0 = GUICtrlCreateTabIt em(" Drive Map ") $CurX = $BaseX $CurY = $BaseY $CurY = $CurY + 10 GuiCtrlCreate Group("Drive Mapping", $CurX+10, $CurY, 580, 135) $CurY = $CurY + 18 GUICtrlCrea teLabel("Letter", $CurX+20, $CurY+3) $hMapLetter = GUICtrlCreateCombo("F:", $Cur X+85, $CurY, 100, 500, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:") $CurY = $CurY + 27 GUICtrlCreateLabe l("UNC Path", $CurX+20, $CurY+3) $hMapShareEdit = GUICtrlCreateInput("\\Server\S harename", $CurX+85, $CurY, 300) $CurY = $CurY + 27 GUICtrlCreateLabel("Username ", $CurX+20, $CurY+3) $hMapUserEdit = GUICtrlCreateInput("Domain.com\%Username%" , $CurX+85, $CurY, 300) $CurY = $CurY + 27 GUICtrlCreateLabel("Password", $CurX+ 20, $CurY+3) $hMapPasswordEdit = GUICtrlCreateInput("Password", $CurX+85, $CurY, 300, -1, $ES_PASSWORD) $hMapButtonGo = GUICtrlCreateButton("&Map!", $BaseX+500, $BaseY+290, 100) ; Capture Tab ; $hTab_1 = GUICtrlCreateTabItem(" Capture ") $CurX = $BaseX $CurY = $BaseY ; File Group $CurY = $CurY + 10 GuiCtrlCreateGroup ("WIM Image", $CurX+10, $CurY, 580, 155) $CurY = $CurY + 18 GUICtrlCreateLabel(" Source", $CurX+20, $CurY+3) $hCaptureSourceEdit = GUICtrlCreateInput("C:", $CurX +85, $CurY, 300) $hCaptureSourceBrowse = GUICtrlCreateButton("Browse", $CurX+395 , $CurY-2) $CurY = $CurY + 27 GUICtrlCreateLabel("Destination", $CurX+20, $CurY+ 3) $hCaptureDestEdit = GUICtrlCreateInput("MyWim.wim", $CurX+85, $CurY, 300) $hC aptureDestBrowse = GUICtrlCreateButton("Browse", $CurX+395, $CurY-2) $CurY = $Cu rY + 27 GUICtrlCreateLabel("Compression", $CurX+20, $CurY+3) $hCaptureCompressio n = GUICtrlCreateCombo("Maximum", $CurX+85, $CurY, 100, 500, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "Fast") $CurY = $CurY + 27 GUICtrlCreateLabel("Name", $CurX+2 0, $CurY+3) $hCaptureNameEdit = GUICtrlCreateInput("My Vista Image", $CurX+85, $ CurY, 300) $CurY = $CurY + 27 GUICtrlCreateLabel("Description", $CurX+20, $CurY+ 3) $hCaptureDescEdit = GUICtrlCreateInput("My Vista Image Description", $CurX+85 , $CurY, 300) ; Options Group $CurY = $CurY + 40 GuiCtrlCreateGroup("Options", $ CurX+10, $CurY, 580, 100) $CurY = $CurY + 18 GUICtrlCreateLabel("/config", $CurX +20, $CurY+3) $hCaptureConfigEdit = GUICtrlCreateInput("", $CurX+85, $CurY, 300) $hCaptureConfigBrowse = GUICtrlCreateButton("Browse", $CurX+395, $CurY-2) $CurY = $CurY + 27 GUICtrlCreateLabel("/flags", $CurX+20, $CurY+3) $hCaptureFlagsEdit = GUICtrlCreateInput("Ultimate", $CurX+85, $CurY, 300) $CurY = $CurY + 27 $hCap tureBootCheck = GUICtrlCreateCheckbox("/boot (WinPE Images Only) ", $CurX+20, $C urY) $hCaptureCheckCheck = GUICtrlCreateCheckbox("/check", $CurX+190, $CurY) $hC aptureButtonGo = GUICtrlCreateButton("&Capture!", $BaseX+500, $BaseY+290, 100) ; ; Apply Tab ; $hTab_2 = GUICtrlCreateTabItem(" Apply ") $CurX = $BaseX $CurY = $BaseY ; File Group $CurY = $CurY + 10 GuiCtrlCreateGroup("WIM Image", $CurX+1 0, $CurY, 580, 205) $CurY = $CurY + 18 GUICtrlCreateLabel("1. Source", $CurX+20, $CurY+3) $hApplySourceEdit = GUICtrlCreateInput("MyWim.wim", $CurX+85, $CurY, 3 00) $hApplySourceBrowse = GUICtrlCreateButton("Browse", $CurX+395, $CurY-2) $Cur Y = $CurY + 27 GUICtrlCreateLabel ("Input Image Number", $CurX+15, $CurY+30, 70, 30) $hApplyName = GUICtrlCreateInput("1", $CurX+85, $CurY+30, 40, 20) $hApplyNa meBrowse= GUICtrlCreateButton("2. Poll Image Number", $CurX+15, $CurY+1) $treevi ew = GUICtrlCreateTreeView ( 150, 90, 450, 120, BitOr($TVS_HASBUTTONS, $TVS_HASL INES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENT
EDGE) $CurY = $CurY + 27 GUICtrlCreateLabel("Destination", $CurX+20, $CurY+103) $hApplyDestEdit = GUICtrlCreateInput("C:", $CurX+85, $CurY+100, 300) $hApplyDest Browse = GUICtrlCreateButton("Browse", $CurX+395, $CurY+98) ; Options Group $Cur Y = $CurY + 40 GuiCtrlCreateGroup("Options", $CurX+10, $CurY+100, 580, 50) $CurY = $CurY + 18 Dim $hReboot = GUICtrlCreateCheckbox ( "Automatically Reboot", $Cu rX+20, $CurY+100, 130,15) $hApplyVerifyCheck = GUICtrlCreateCheckbox("/verify", $CurX+150, $CurY+100, 100, 15 ) GUICtrlSetState ($hReboot, $GUI_CHECKED) $hApply ButtonGo = GUICtrlCreateButton("&Apply!", $BaseX+500, $BaseY+290, 100) ; ; Set D efault Options ; LoadSettings() SettingsToGUI() ; ; The GUI message loop ; GuiSe tState() While 1 $msg = GuiGetMsg() Select ; General Messages Case $msg = $GUI_EVENT_CLOSE ExitLoop ; Capture Messages Case $msg = $hCaptureButtonGo DoCapture() Case $msg = $hCaptureSourceBrowse $sDir = BrowseForDirector y() if $sDir Then GUICtrlSetData($hCaptureSourceEdit, $sDir) Case $msg = $hCaptureDestBrowse $sFile = BrowseForWimToSave() if $sFile Then GUICtrlSetData($hCaptureDestEdit, $sFile) Case $ms g = $hCaptureConfigBrowse $sFile = BrowseForConfig() If $sFile Then GUICtrlSetData($hCaptureConfigEdit, $sFile) ; Apply Mess ages Case $msg = $hApplyNameBrowse PollImage() Case $msg = $hApplyButtonGo DoApply() Case $msg = $hApplyDestBrow se $sDir = BrowseForDirectory() if $sDir Then GUICtrlSet Data($hApplyDestEdit, $sDir) Case $msg = $hApplySourceBrowse $sFile = BrowseForWimToLoad() if $sFile Then GUICtrlSetData($hApply SourceEdit, $sFile) ; Drive Map Messages Case $msg = $hMapBu ttonGo DoMapping() Case Else ;;; EndSelect W End Exit ; ; FUNCTIONS ; Func BrowseForDirectory() $sDir = FileSelectFolder( "Select source folder", "C:") If StringRight($sDir, 1) = "\" Then $sDir = St ringTrimRight($sDir, 1) Return $sDir EndFunc Func BrowseForWimToSave() $ sFile = FileSaveDialog( "Select destination file", "C:\", "WIM Files (*.wim)", 3 ) If @error Then Return "" If StringRight($sFile, 4) <> ".wIM" Then $sFile = $sFile & ".wim" Return $sFile EndFunc Func BrowseForWimToLoad() $sFile = FileOpenDialog( "Select source file", "C:\", "WIM Files (*.wim)", 3) If @error Then Return "" Return $sFile EndFunc Func BrowseForConfig() $sFile = FileOpenDialog("Select config file", @ScriptDir, "INI files (*.ini)", 1) If @error Or StringRight($sFile, 4) <> ".ini" Then Return "" Return $ sFile EndFunc Func DoCapture() $sCmd = '"' & @ScriptDir & '\imagex.exe"' If $gCaptureConfig <> "" Then $sCmd = $sCmd & ' /config "' & $gCaptureConfi g & '"' If $gCaptureCompression = "fast" Then $sCmd = $sCmd & " /compress fast" Else $sCmd = $sCmd & " /compress maximum" EndIf If $gCaptureCheck = 1 Then $sCmd = $sCmd & " /check" If $gCaptureBoo t = 1 Then $sCmd = $sCmd & " /boot" If $gCaptureFlags <> "" Then $sCmd = $sC md & ' /flags "' & $gCaptureFlags & '"' $sCmd = $sCmd & ' /capture "' & $gCaptureSource & '" "' & $gCaptureDestination & '"' $sCmd = $sCmd & ' "' & $gCaptureName & '" "' & $gCaptureDescription & '"' $ret = RunWait($sCmd, @WorkingDir, @SW_SHOW) SplashTextOn ( "Return Code", "Imagex.exe returned w ith code = " & $ret, 400, 200, -1, -1, 32, "Tahoma", 16, 500) sleep (3000) SplashOff () EndFunc Func PollImage () Dim $nitem, $nitem Dim $imagei nfo = " " $read = GUICtrlRead ($hApplySourceEdit) $sCmd = "imagex.exe" If $read = "" Then MsgBox (48, "Input required", "Please select the s ource") Else $sCmd = $sCmd & ' /info "' & $read & '"' EndIf ;MsgBox(0, "scmd", $sCmd) Dim $ret = Run(@ComSpec & " /c " & $sCmd & '"', @S criptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD ) While 1 $line = Stdo utRead($ret) If $line = "" Then ExitLoop $imageinfo = $imageinfo & $ line ;MsgBox(0, "RunDOS", $line) If @error Then ExitLoop WEnd _ GUICtrlTreeViewDeleteAllItems ($treeview) $aImageInfo = _StringBetween ( $im ageinfo, "<name>", "</name>" ) $aImageDesc = _StringBetween ( $imageinfo, "< Description>", "</Description>" ) $aImageFileCount = _StringBetween ( $image info, "<Filecount>", "</Filecount>" ) $aImageBuild = _StringBetween ( $image info, "<Build>", "</Build>" ) $imagenumber = UBound ($aImageInfo, 1) $x = 0 Dim $nitem[$imagenumber] Do $nitem[$x] = GUICtrlCreateTreeViewIt
em ( "Image " & $x +1 & ": " & $aImageInfo[$x], $treeview ) GUICtrlCreateTre eViewItem ( "Description: " & $aImageDesc [$x], $nitem[$x] ) GUICtrlCreateTr eeViewItem ( "File Count: " & $aImageFileCount [$x], $nitem[$x] ) GUICtrlCre ateTreeViewItem ( "Build Version: " & $aImageBuild [$x], $nitem[$x] ) GUICtr lSetState($nitem[$x], $GUI_DEFBUTTON) $x = $x + 1 Until $x = $imagenumbe r EndFunc Func DoApply() $sCmd = '"' & @ScriptDir & '\imagex.exe"' I f $gApplyVerify = 1 Then $sCmd = $sCmd & " /verify" $sCmd = $sCmd & ' /a pply "' & $gApplySource & '" "' & $gApplyName & '" "' & $gApplyDestination & '"' $ret = RunWait($sCmd, @WorkingDir, @SW_SHOW) SplashTextOn ( "Return Cod e", "Imagex.exe returned with code = " & $ret, 400, 200, -1, -1, 32, "Tahoma", 1 6, 500) sleep (3000) SplashOff () $Rebootstate = GUICtrlRead ($hRebo ot) If $Rebootstate = 1 Then _RunDOS("Start wpeutil reboot") EndIf E ndFunc Func DoMapping() $gMapLetter = IniRead($sIni, "MAP", "Letter", "V:") DriveMapDel($gMapLetter) $gMapShare = IniRead($sIni, "Map", "Share", "") $VistaAccount = GUICtrlRead ( $hMapUserEdit ) $VistaPwd = GUICtrlRead ( $hMapPasswordEdit ) $res = DriveMapAdd($gMapLetter, $gMapShare, 0, $VistaAc count, $VistaPwd) If $res Then ControlSetText("Mapping Drive", " ", "Static1", "Drive successfully mapped!" ) sleep (2000) ;MsgBo x(64, "Drive Mapping", "Drive successfully mapped!") Else SplashOff( ) MsgBox(16, "Drive Mapping", "Error mapping drive! Code: " & $avDriveMa pAdd[@error]) EndIf EndFunc Func LoadSettings() $sIni = @Scrip tDir & "\gimagex.ini" $gCaptureSource = IniRead($sIni, "CAPTURE", "Sourc e", "C:") $gCaptureDestination = IniRead($sIni, "CAPTURE", "Destination", "M yWim.wim") $gCaptureCompression = IniRead($sIni, "CAPTURE", "Compression", " Maximum") $gCaptureFlags = IniRead($sIni, "CAPTURE", "Flags", "Ultimate") $gCaptureConfig = IniRead($sIni, "CAPTURE", "Config", "") $gCaptureBoot = IniRead($sIni, "CAPTURE", "Boot", "0") $gCaptureCheck = IniRead($sIni, "CAPT URE", "Check", "1") $gCaptureName = IniRead($sIni, "CAPTURE", "Name", "My Vi sta Build Name") $gCaptureDescription = IniRead($sIni, "CAPTURE", "Descripti on", "My Vista Build Description") $gApplySource = IniRead($sIni, "APPLY", " Source", "C:") $gApplyDestination = IniRead($sIni, "APPLY", "Destination", " MyWim.wim") $gApplyVerify = IniRead($sIni, "APPLY", "Verify", "0") $gApp lyName = IniRead($sIni, "APPLY", "Name", "My Vista Build Name") $gMapLetter = IniRead($sIni, "MAP", "Letter", "M:") $gMapShare = IniRead($sIni, "MAP", " Share", "\\Server\Share") $gMapUser = IniRead($sIni, "MAP", "User", "User") EndFunc Func SettingsToGUI() ; CAPTURE GUICtrlSetData($hCaptureSourceEdi t, $gCaptureSource) GUICtrlSetData($hCaptureDestEdit, $gCaptureDestination) GUICtrlSetData($hCaptureCompression, $gCaptureCompression) GUICtrlSetDat a($hCaptureFlagsEdit, $gCaptureFlags) GUICtrlSetData($hCaptureConfigEdit, $g CaptureConfig) If $gCaptureBoot = 1 Then GUICtrlSetState($hCaptureBo otCheck, $GUI_CHECKED) Else GUICtrlSetState($hCaptureBootCheck, $GUI _UNCHECKED) EndIf If $gCaptureCheck = 1 Then GUICtrlSetState($hC aptureCheckCheck, $GUI_CHECKED) Else GUICtrlSetState($hCaptureCheckC heck, $GUI_UNCHECKED) EndIf GUICtrlSetData($hCaptureNameEdit, $gCaptureN ame) GUICtrlSetData($hCaptureDescEdit, $gCaptureDescription) ; APPLY GUICtrlSetData($hApplySourceEdit, $gApplySource) GUICtrlSetData($hApply DestEdit, $gApplyDestination) If $gApplyVerify = 1 Then GUICtrlSetSt ate($hApplyVerifyCheck, $GUI_CHECKED) Else GUICtrlSetState($hApplyVe rifyCheck, $GUI_UNCHECKED) EndIf GUICtrlSetData($hApplyName, $gApplyName ) ; MAP GUICtrlSetData($hMapLetter, $gMapLetter) GUICtrlSetData($hMa pShareEdit, $gMapShare) GUICtrlSetData($hMapUserEdit, $gMapUser) GUICtrl SetData($hMapPasswordEdit, $gMapPassword) EndFunc