AmbientMike Posted April 15, 2012 Share Posted April 15, 2012 Guys, Hope you can help. I'm trying to make my own GUI for ImageX (I know of GImageX but it's way more than I want / need so I'm trying to make my own basic one for applying WIM images. I'm doing OK (for a virginal AutoIt coder but running into a problem with my drop-down list by which I'm hoping to set the destination disk drive to. Basically the drop-down list shows all available drives but only on one line so they're not selectable as individual drives. Any clues where I'm going wrong? Here's my code so far... expandcollapse popup#include <GUIConstantsEx.au3> Local $WIMFile = "NO WIM FILE CHOSEN" Local $SelectedDrive = 0 Opt("GUIOnEventMode", 1) $mainwindow = GUICreate("ImageX GUI", 550, 400) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("1 - Please select a WIM file to restore HDD from...", 30, 10) $SelectWIMButton = GUICtrlCreateButton("Browse to a WIM file", 30, 30, 150) GUICtrlSetOnEvent($SelectWIMButton, "SelectWIMButton") ; COMBO BOX CREATION GUICtrlCreateLabel("2 - Select which hard drive you want to image...", 30, 90) $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive") $sResult = "" For $objItem In $colItems $sResult &= "Drive No. " & stringright($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & @CR Next $ComboResult = GUICtrlCreateCombo("", 30, 110, 490) GUICtrlSetData($ComboResult, $sResult) ; END OF COMBO BOX GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive, 30, 325) GUICtrlCreateLabel("Current Command Line to be run...", 30, 355) GUICtrlCreateLabel("X:\Windows\System32\Imagex64.exe /apply " & $WIMFile & "1 W:\", 30, 370) ; Keeps GUI Open While 1 Sleep(1000) WEnd Func SelectWIMButton() Local $WIMFile = FileOpenDialog("Select WIM File To Restore From", @WindowsDir & "\", "Microsoft WIM Files (*.WIM)", 1 + 4) If @error Then Else $WIMFile = StringReplace($WIMFile, "|", @CRLF) $COMMAND = GUICtrlCreateLabel("X:\Windows\System32\Imagex64.exe /apply " & $WIMFile & "1 W:\", 30, 370) EndIf EndFunc Func CLOSEClicked() Exit EndFunc Link to comment Share on other sites More sharing options...
water Posted April 15, 2012 Share Posted April 15, 2012 (edited) You have to separate each line by a pipe character ("|") $sResult &= "Drive No. " & stringright($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & "|" Edited April 15, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AmbientMike Posted April 15, 2012 Author Share Posted April 15, 2012 (edited) That's brilliant (and surprisingly easy). Thankyou very much kind sir. Are the contents of the drop-down box available as a local variable somewhere in there also? I want the drive number so "StringLeft($VAR, 11) Which $VAR do I need or does a new one need creating in this case? I thought it would be $ComboResult but that seems to be the whole string, not the selected one... Edited April 15, 2012 by AmbientMike Link to comment Share on other sites More sharing options...
water Posted April 15, 2012 Share Posted April 15, 2012 Use function GUICtrlRead to get the value of the selected entry. The help file explains how. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AmbientMike Posted April 15, 2012 Author Share Posted April 15, 2012 Thanks - that's really helped. What I'd like to do now is when something is selected in the drop-down combo list it automatically populates a variable and updates a GUICtrlCreateLabel. I've added a button to do this manually but would like it to happen upon selection of a disk drive form the drop-down box. I am trying to use the While and GUIGetMsg (at the very end of the code). I've seen some test code that does something similar and read the help file until my eyes have gone blurred but I'm again at a loss Here is my current code.. expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $WIMFile = "NO WIM FILE CHOSEN" Dim $SelectedDrive Dim $SelectedDrive2 Opt("GUIOnEventMode", 1) $mainwindow = GUICreate("ImageX GUI", 550, 400) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Current Command Line to be run...", 30, 355) GUICtrlCreateLabel("X:\Windows\System32\Imagex64.exe /apply " & $WIMFile & "1 W:\", 30, 370) GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) ; Slect WIM Button GUICtrlCreateLabel("1 - Please select a WIM file to restore HDD from...", 30, 10) $SelectWIMButton = GUICtrlCreateButton("Browse to a WIM file", 30, 32, 150) GUICtrlSetOnEvent($SelectWIMButton, "SelectWIMButton") Func SelectWIMButton() Local $WIMFile = FileOpenDialog("Select WIM File To Restore From", @WindowsDir & "\", "Microsoft WIM Files (*.WIM)", 1 + 4) If @error Then Else $WIMFile = StringReplace($WIMFile, "|", @CRLF) $COMMAND = GUICtrlCreateLabel("X:\Windows\System32\Imagex64.exe /apply " & $WIMFile & " 1 W:\", 30, 370) EndIf EndFunc ; COMBO BOX CREATION GUICtrlCreateLabel("2 - Select destination drive (normally disk 0).", 30, 90) $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive") $sResult = "" For $objItem In $colItems $sResult &= "Drive No. " & stringright($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & "|" Next $ComboResult = GUICtrlCreateCombo("", 30, 112, 300) ; This creates the drop-down list GUICtrlSetData($ComboResult, $sResult) ; This populates the list ; END OF COMBO BOX ; Create Apply Button GUICtrlCreateLabel("3 - Apply target hard disk selction", 350, 90) $ApplyDisk = GUICtrlCreateButton("Apply", 350, 110, 50) GUICtrlSetOnEvent($ApplyDisk, "ApplyDiskButton") Func ApplyDiskButton() $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Letter GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) EndFunc ; Keeps GUI Open While 1 Sleep(1000) WEnd Func CLOSEClicked() Exit EndFunc ; Test auto update field with contents of combo box While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case GUIGetMsg() = $ComboResult $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Letter GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Zedna Posted April 15, 2012 Share Posted April 15, 2012 (edited) You mixed wrong Msg and Event mode in your GUI. Either use one or other not both together. If you use Event mode then add GUICtrlSetOnOvent() for your combobox as you did for your button. I think you should read some basics in helpfile before such quick/wrong scripting. Also look at DriveGetDrive() function which can give you list of drives in simple way. Edited April 15, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
AmbientMike Posted April 15, 2012 Author Share Posted April 15, 2012 DriveGetDrive() actually seems to return partitions. I want to list and be able to select actual install hard disks, not partitions as the script that this GUI will eventually run will wipe and re-partition a disk using the DISKPART command which needs disk numbers as returned by the Win32_DiskDrive API. I appreciate that I need to read the basics but I'm not from a programming background and as I'm sure you'll appreciate it takes a bit of getting your head around this stuff and I don't really have a great deal of time. Do you have an example of a quick edit to get it working? Link to comment Share on other sites More sharing options...
Zedna Posted April 15, 2012 Share Posted April 15, 2012 (edited) expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $WIMFile = "NO WIM FILE CHOSEN" Dim $SelectedDrive Dim $SelectedDrive2 Opt("GUIOnEventMode", 1) $mainwindow = GUICreate("ImageX GUI", 550, 400) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Current Command Line to be run...", 30, 355) GUICtrlCreateLabel("X:WindowsSystem32Imagex64.exe /apply " & $WIMFile & "1 W:", 30, 370) GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) ; Slect WIM Button GUICtrlCreateLabel("1 - Please select a WIM file to restore HDD from...", 30, 10) $SelectWIMButton = GUICtrlCreateButton("Browse to a WIM file", 30, 32, 150) GUICtrlSetOnEvent($SelectWIMButton, "SelectWIMButton") Func SelectWIMButton() Local $WIMFile = FileOpenDialog("Select WIM File To Restore From", @WindowsDir & "", "Microsoft WIM Files (*.WIM)", 1 + 4) If @error Then Else $WIMFile = StringReplace($WIMFile, "|", @CRLF) $COMMAND = GUICtrlCreateLabel("X:WindowsSystem32Imagex64.exe /apply " & $WIMFile & " 1 W:", 30, 370) EndIf EndFunc ;==>SelectWIMButton ; COMBO BOX CREATION GUICtrlCreateLabel("2 - Select destination drive (normally disk 0).", 30, 90) $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $strComputer & "rootcimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive") $sResult = "" For $objItem In $colItems $sResult &= "Drive No. " & StringRight($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & "|" Next $ComboResult = GUICtrlCreateCombo("", 30, 112, 300) ; This creates the drop-down list GUICtrlSetData($ComboResult, $sResult) ; This populates the list GUICtrlSetOnEvent($ComboResult, "OnComboChange") Func OnComboChange() $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Letter GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) EndFunc ; END OF COMBO BOX ; Create Apply Button GUICtrlCreateLabel("3 - Apply target hard disk selction", 350, 90) $ApplyDisk = GUICtrlCreateButton("Apply", 350, 110, 50) GUICtrlSetOnEvent($ApplyDisk, "ApplyDiskButton") Func ApplyDiskButton() $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Letter GUICtrlCreateLabel("Current Drive selected as destination = " & $SelectedDrive2, 30, 325) EndFunc ;==>ApplyDiskButton ; Keeps GUI Open While 1 Sleep(100) WEnd Func CLOSEClicked() Exit EndFunc ;==>CLOSEClicked Edited April 15, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
AmbientMike Posted April 15, 2012 Author Share Posted April 15, 2012 Thanks - that's great. It really is appreciated Link to comment Share on other sites More sharing options...
Zedna Posted April 15, 2012 Share Posted April 15, 2012 There are other errors/mistakes - in functions use GUICtrlSetData instead of GUICtrlCreateLabel for changing texts of labels Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
AmbientMike Posted May 15, 2012 Author Share Posted May 15, 2012 (edited) Hi... Bit of a follow up question to this one. I've done a bit more to the script recently and added some tabs. The scripts are 100% working (I know they aren't the neatest and could probably be helped from a bit of a re-write) but the issue I'm having now is that the GUI loads but the contents of the first tab appears to be empty until you switch tabs when it seems to draw it all in. Is there a way to force a re-draw or something to avoid the need for a tab-swap every launch? expandcollapse popup#include <GUIConstantsEx.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Constants.au3> #include <Array.au3> $WIMFile = "NO WIM FILE CHOSEN" $ImageXFile = "X:WindowsSystem32Imagex64.exe" $SelectedDrive2 = "No Drive Selected" $YN = "Yes" $WIMLocated = "No" $ImageXLocated = "No" $ImageXFilename = "imagex64.exe" $SelctedDriveLetter = "0" $CapVar = "0" $DescResult = "0" $Verify = "/Verify" Local $hGUI, $hPen, $hGraphic ;Moved this to the top to stop problems with rendering $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $strComputer & "rootcimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive") $sResult = "" For $objItem In $colItems $sResult &= "Drive No. " & StringRight($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & "|" Next Opt("GUIOnEventMode", 1) Opt("TrayIconHide", 1) GUICreate("ImageX GUI", 410, 475) GUICtrlCreateTab(10, 10, 390, 455) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tab 1 $tab1 = GUICtrlCreateTabItem("Apply") ; Select WIM Button GUICtrlCreateLabel("1 - Please select a WIM file to restore HDD from...", 30, 60) $SelectWIMButton = GUICtrlCreateButton("Browse to a WIM file", 30, 82, 120) GUICtrlSetOnEvent($SelectWIMButton, "SelectWIMButton") $Check1 = 0 Func SelectWIMButton() $WIMFile = FileOpenDialog("Select WIM File To Restore From", @HomeDrive & "", "Microsoft WIM Files (*.WIM)", 1 + 4) If @Error Then Else $WIMFile = StringReplace($WIMFile, "|", @CRLF) $WIMLocated = "Yes" EndIf EndFunc ; COMBO BOX CREATION FOR DRIVE SELECTION GUICtrlCreateLabel("2 - Select destination drive to appy image to (normally disk 0).", 30, 140) $ComboResult = GUICtrlCreateCombo("", 30, 162, 350) ; This creates the drop-down list GUICtrlSetData($ComboResult, $sResult) ; This populates the list GUICtrlSetOnEvent($ComboResult, "OnComboChange") Func OnComboChange() $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Number EndFunc ; CHECK BOXES TO SELECT REBOOT GUICtrlCreateLabel("3 - Reboot PC when re-image is complete?", 30, 220) $YesBox = GUICtrlCreateCheckbox("Yes", 30, 242, 50, 20) GUICtrlSetState($YesBox,$GUI_CHECKED) $NoBox = GUICtrlCreateCheckbox("No", 80, 242, 50, 20) GUICtrlSetOnEvent($YesBox, "YesPressed") GUICtrlSetOnEvent($NoBox, "NoPressed") Func YesPressed() $YN = "Yes" GUICtrlSetState($NoBox,$GUI_UNCHECKED) EndFunc Func NoPressed() $YN = "No" GUICtrlSetState($YesBox,$GUI_UNCHECKED) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Apply Image GUICtrlCreateLabel("4 - Apply WIM image to selected drive", 30, 300) $ApplyButton = GUICtrlCreateButton("Apply", 30, 322, 120) GUICtrlSetOnEvent($ApplyButton, "ApplyButton") Func ApplyButton() $DefReboot = 0 $Check = 0 If $WIMLocated = "No" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No WIM file has been selected") $Check = 1 EndIf If $SelectedDrive2 = "No Drive Selected" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No destination drive selected") $Check = 1 EndIf If $ImageXLocated = "No" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "ImageX.exe Not Found") $Check = 1 EndIf If $Check = 0 Then $ContinueAnswer = MsgBox(4, "Ready To Start", "This will wipe the selected hard disk and apply the selected image." & @CRLF & @CRLF & "Do you want to continue?") Switch $ContinueAnswer Case 6; Yes IF FileExists (@TempDir & "DiskPartScript.txt") Then FileDelete (@TempDir & "DiskPartScript.txt") EndIf $DiskPartScript = FileOpen(@TempDir & "DiskPartScript.txt", 1) FileWrite ($DiskPartScript, "select disk " & $SelectedDrive2 & @CRLF) FileWrite ($DiskPartScript, "clean" & @CRLF) FileWrite ($DiskPartScript, "create partition primary size=100" & @CRLF) FileWrite ($DiskPartScript, 'format quick fs=ntfs label="System"' & @CRLF) FileWrite ($DiskPartScript, 'assign letter="S"' & @CRLF) FileWrite ($DiskPartScript, "active" & @CRLF) FileWrite ($DiskPartScript, "create partition primary" & @CRLF) FileWrite ($DiskPartScript, 'format quick fs=ntfs label="Windows"' & @CRLF) FileWrite ($DiskPartScript, 'assign letter="W"') FileClose ($DiskPartScript) $COMMAND = String($ImageXFile & " /apply " & '"' & $WIMFile & '"' & " 1 W:") RunWait(@SystemDir & 'DiskPart /s ' & @TempDir & 'DiskPartScript.txt', "") If WinExists("[TITLE:AutoPlay]") THEN WinClose("[TITLE:AutoPlay]") EndIf If WinExists("[TITLE:AutoPlay]") THEN WinClose("[TITLE:AutoPlay]") EndIf Run($COMMAND, "") RunWait(@WindowsDir & "System32bcdboot.exe W:Windows /l en-US /s S:", "") IF $YN = "Yes" Then $ContinueReboot = MsgBox(4, "Rebooting PC...", "PC will restart in 10 seconds." & @CRLF & @CRLF & "Do you want to allow reboot?", 10) Switch $ContinueReboot Case 6; Yes Run(@SystemDir & "Shutdownpe.exe /restart", "") Run(@WindowsDir & "system32shutdown.exe -r -t 00", "") Exit Case 7; No Return EndSwitch $DefReboot = 1 EndIf Case 7; No Return EndSwitch EndIf If $DefReboot = 1 Then Run(@SystemDir & "Shutdownpe.exe /restart", "") Run(@WindowsDir & "system32shutdown.exe -r -t 00", "") EndIf EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tab 2 $tab2 = GUICtrlCreateTabItem("Capture") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Select Drive To Capture GUICtrlCreateLabel("1 - Please select the letter of the drive you wish to capture...", 30, 60) $DriveArray = DriveGetDrive("FIXED") $DriveString = _ArrayToString($DriveArray, "|", 1) $DriveCombo = GUICtrlCreateCombo("", 30, 82, 350) GUICtrlSetData(-1, $DriveString) GUICtrlSetOnEvent($DriveCombo, "DriveSelect") Func DriveSelect() $SelctedDriveLetter = GUICtrlRead($DriveCombo) ; This reads the contents of the box $SDL = $SelctedDriveLetter EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Select Destination file GUICtrlCreateLabel("2 - Select destination file to capture image to", 30, 140) $SelectWIMDestinationButton = GUICtrlCreateButton("Browse to Destination", 30, 162, 120) GUICtrlSetOnEvent($SelectWIMDestinationButton, "SetDestination") Func SetDestination() $CapVar = FileSaveDialog("Browse to Where you want to save the WIM", @HomeDrive, "WIM File (*.wim)", 2 + 16, "capture") If @error Then MsgBox(4096, "", "No File(s) chosen") Else $CapVar = StringReplace($CapVar & ".wim", "|", @CRLF) EndIf EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Input nick name of file GUICtrlCreateLabel("3 - Enter description of image", 30, 220) $Description = GUICtrlCreateButton("Enter Description", 30, 242, 120) GUICtrlSetOnEvent($Description, "EnterDesc") Func EnterDesc() $DescResult = InputBox ( "Enter Description", "Enter Description of the image to be captured") If @error Then MsgBox(4096, "", "No Description Provided") Else ;MsgBox(4096, "", $DescResult) EndIf EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Verify or not GUICtrlCreateLabel("4 - Verify Iimage During Capture?", 30, 300) $YesBoxC = GUICtrlCreateCheckbox("Yes", 30, 322, 50, 20) GUICtrlSetState($YesBoxC,$GUI_CHECKED) $NoBoxC = GUICtrlCreateCheckbox("No", 80, 322, 50, 20) GUICtrlSetOnEvent($YesBoxC, "YesPressedC") GUICtrlSetOnEvent($NoBoxC, "NoPressedC") Func YesPressedC() $Verify = "/Verify" GUICtrlSetState($NoBoxC,$GUI_UNCHECKED) EndFunc Func NoPressedC() $Verify = "" GUICtrlSetState($YesBoxC,$GUI_UNCHECKED) EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Start The Capture GUICtrlCreateLabel("5 - Start Capturing Image...", 30, 380) $CaptureButton = GUICtrlCreateButton("Capture Image", 30, 402, 120) GUICtrlSetOnEvent($CaptureButton, "CaptureButton") Func CaptureButton() $CapCommand = String("imagex64.exe /capture " & $SelctedDriveLetter & " " & '"' & $CapVar & '"' & " " & '"' & $DescResult & '"' & " " & $Verify) $CheckC = 0 If $SelctedDriveLetter = "0" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No source drive has been selected") $CheckC = 1 EndIf If $CapVar = "0" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No destination file has been selected") $CheckC = 1 EndIf If $DescResult = "0" Then MsgBox(0+262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No image description provided") $CheckC = 1 EndIf If $CheckC = 0 Then While ProcessExists "explorer.exe" ProcessClose ( "explorer.exe" ) WEnd Run($CapCommand, "") EndIf EndFunc While 1 WEnd Func CLOSEClicked() Exit EndFunc Edited May 15, 2012 by AmbientMike Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 AmbientMike,You had not closed the tab creation structure which was giving you problems. Once I closed the structure and displayed the GUI after that had been done the tabs work fine for me (look for the <<<<<<<<<<<<<< lines): expandcollapse popup#include <GUIConstantsEx.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Constants.au3> #include <Array.au3> $WIMFile = "NO WIM FILE CHOSEN" $ImageXFile = "X:WindowsSystem32Imagex64.exe" $SelectedDrive2 = "No Drive Selected" $YN = "Yes" $WIMLocated = "No" $ImageXLocated = "No" $ImageXFilename = "imagex64.exe" $SelctedDriveLetter = "0" $CapVar = "0" $DescResult = "0" $Verify = "/Verify" Local $hGUI, $hPen, $hGraphic ;Moved this to the top to stop problems with rendering $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $strComputer & "rootcimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive") $sResult = "" For $objItem In $colItems $sResult &= "Drive No. " & StringRight($objItem.DeviceID, 1) & " : " & Int($objItem.Size / 1024 ^ 3) & " GB " & " : " & ($objItem.Caption) & "|" Next Opt("GUIOnEventMode", 1) ;Opt("TrayIconHide", 1) GUICreate("ImageX GUI", 410, 475) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateTab(10, 10, 390, 455) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tab 1 $tab1 = GUICtrlCreateTabItem("Apply") ; Select WIM Button GUICtrlCreateLabel("1 - Please select a WIM file to restore HDD from...", 30, 60) $SelectWIMButton = GUICtrlCreateButton("Browse to a WIM file", 30, 82, 120) GUICtrlSetOnEvent($SelectWIMButton, "SelectWIMButton") $Check1 = 0 ; COMBO BOX CREATION FOR DRIVE SELECTION GUICtrlCreateLabel("2 - Select destination drive to appy image to (normally disk 0).", 30, 140) $ComboResult = GUICtrlCreateCombo("", 30, 162, 350) ; This creates the drop-down list GUICtrlSetData($ComboResult, $sResult) ; This populates the list GUICtrlSetOnEvent($ComboResult, "OnComboChange") ; CHECK BOXES TO SELECT REBOOT GUICtrlCreateLabel("3 - Reboot PC when re-image is complete?", 30, 220) $YesBox = GUICtrlCreateCheckbox("Yes", 30, 242, 50, 20) GUICtrlSetState($YesBox, $GUI_CHECKED) $NoBox = GUICtrlCreateCheckbox("No", 80, 242, 50, 20) GUICtrlSetOnEvent($YesBox, "YesPressed") GUICtrlSetOnEvent($NoBox, "NoPressed") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Apply Image GUICtrlCreateLabel("4 - Apply WIM image to selected drive", 30, 300) $ApplyButton = GUICtrlCreateButton("Apply", 30, 322, 120) GUICtrlSetOnEvent($ApplyButton, "ApplyButton") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tab 2 $tab2 = GUICtrlCreateTabItem("Capture") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Select Drive To Capture GUICtrlCreateLabel("1 - Please select the letter of the drive you wish to capture...", 30, 60) $DriveArray = DriveGetDrive("FIXED") $DriveString = _ArrayToString($DriveArray, "|", 1) $DriveCombo = GUICtrlCreateCombo("", 30, 82, 350) GUICtrlSetData(-1, $DriveString) GUICtrlSetOnEvent($DriveCombo, "DriveSelect") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Select Destination file GUICtrlCreateLabel("2 - Select destination file to capture image to", 30, 140) $SelectWIMDestinationButton = GUICtrlCreateButton("Browse to Destination", 30, 162, 120) GUICtrlSetOnEvent($SelectWIMDestinationButton, "SetDestination") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Input nick name of file GUICtrlCreateLabel("3 - Enter description of image", 30, 220) $Description = GUICtrlCreateButton("Enter Description", 30, 242, 120) GUICtrlSetOnEvent($Description, "EnterDesc") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Verify or not GUICtrlCreateLabel("4 - Verify Iimage During Capture?", 30, 300) $YesBoxC = GUICtrlCreateCheckbox("Yes", 30, 322, 50, 20) GUICtrlSetState($YesBoxC, $GUI_CHECKED) $NoBoxC = GUICtrlCreateCheckbox("No", 80, 322, 50, 20) GUICtrlSetOnEvent($YesBoxC, "YesPressedC") GUICtrlSetOnEvent($NoBoxC, "NoPressedC") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Start The Capture GUICtrlCreateLabel("5 - Start Capturing Image...", 30, 380) $CaptureButton = GUICtrlCreateButton("Capture Image", 30, 402, 120) GUICtrlSetOnEvent($CaptureButton, "CaptureButton") GUICtrlCreateTabItem("") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState(@SW_SHOW) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Sleep(10) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WEnd Func CLOSEClicked() Exit EndFunc ;==>CLOSEClicked Func SelectWIMButton() $WIMFile = FileOpenDialog("Select WIM File To Restore From", @HomeDrive & "", "Microsoft WIM Files (*.WIM)", 1 + 4) If @error Then Else $WIMFile = StringReplace($WIMFile, "|", @CRLF) $WIMLocated = "Yes" EndIf EndFunc ;==>SelectWIMButton Func OnComboChange() $GetAllDriveInfo = GUICtrlRead($ComboResult) ; This reads the contents of the box $SelectedDrive = StringLeft($GetAllDriveInfo, 11) ;This picks the 1st 11 characters $SelectedDrive2 = StringRight($SelectedDrive, 1) ;This picks the Drive Number EndFunc ;==>OnComboChange Func YesPressed() $YN = "Yes" GUICtrlSetState($NoBox, $GUI_UNCHECKED) EndFunc ;==>YesPressed Func NoPressed() $YN = "No" GUICtrlSetState($YesBox, $GUI_UNCHECKED) EndFunc ;==>NoPressed Func ApplyButton() $DefReboot = 0 $Check = 0 If $WIMLocated = "No" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No WIM file has been selected") $Check = 1 EndIf If $SelectedDrive2 = "No Drive Selected" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No destination drive selected") $Check = 1 EndIf If $ImageXLocated = "No" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "ImageX.exe Not Found") $Check = 1 EndIf If $Check = 0 Then $ContinueAnswer = MsgBox(4, "Ready To Start", "This will wipe the selected hard disk and apply the selected image." & @CRLF & @CRLF & "Do you want to continue?") Switch $ContinueAnswer Case 6; Yes If FileExists(@TempDir & "DiskPartScript.txt") Then FileDelete(@TempDir & "DiskPartScript.txt") EndIf $DiskPartScript = FileOpen(@TempDir & "DiskPartScript.txt", 1) FileWrite($DiskPartScript, "select disk " & $SelectedDrive2 & @CRLF) FileWrite($DiskPartScript, "clean" & @CRLF) FileWrite($DiskPartScript, "create partition primary size=100" & @CRLF) FileWrite($DiskPartScript, 'format quick fs=ntfs label="System"' & @CRLF) FileWrite($DiskPartScript, 'assign letter="S"' & @CRLF) FileWrite($DiskPartScript, "active" & @CRLF) FileWrite($DiskPartScript, "create partition primary" & @CRLF) FileWrite($DiskPartScript, 'format quick fs=ntfs label="Windows"' & @CRLF) FileWrite($DiskPartScript, 'assign letter="W"') FileClose($DiskPartScript) $COMMAND = String($ImageXFile & " /apply " & '"' & $WIMFile & '"' & " 1 W:") RunWait(@SystemDir & 'DiskPart /s ' & @TempDir & 'DiskPartScript.txt', "") If WinExists("[TITLE:AutoPlay]") Then WinClose("[TITLE:AutoPlay]") EndIf If WinExists("[TITLE:AutoPlay]") Then WinClose("[TITLE:AutoPlay]") EndIf Run($COMMAND, "") RunWait(@WindowsDir & "System32bcdboot.exe W:Windows /l en-US /s S:", "") If $YN = "Yes" Then $ContinueReboot = MsgBox(4, "Rebooting PC...", "PC will restart in 10 seconds." & @CRLF & @CRLF & "Do you want to allow reboot?", 10) Switch $ContinueReboot Case 6; Yes Run(@SystemDir & "Shutdownpe.exe /restart", "") Run(@WindowsDir & "system32shutdown.exe -r -t 00", "") Exit Case 7; No Return EndSwitch $DefReboot = 1 EndIf Case 7; No Return EndSwitch EndIf If $DefReboot = 1 Then Run(@SystemDir & "Shutdownpe.exe /restart", "") Run(@WindowsDir & "system32shutdown.exe -r -t 00", "") EndIf EndFunc ;==>ApplyButton Func DriveSelect() $SelctedDriveLetter = GUICtrlRead($DriveCombo) ; This reads the contents of the box $SDL = $SelctedDriveLetter EndFunc ;==>DriveSelect Func SetDestination() $CapVar = FileSaveDialog("Browse to Where you want to save the WIM", @HomeDrive, "WIM File (*.wim)", 2 + 16, "capture") If @error Then MsgBox(4096, "", "No File(s) chosen") Else $CapVar = StringReplace($CapVar & ".wim", "|", @CRLF) EndIf EndFunc ;==>SetDestination Func EnterDesc() $DescResult = InputBox("Enter Description", "Enter Description of the image to be captured") If @error Then MsgBox(4096, "", "No Description Provided") Else ;MsgBox(4096, "", $DescResult) EndIf EndFunc ;==>EnterDesc Func YesPressedC() $Verify = "/Verify" GUICtrlSetState($NoBoxC, $GUI_UNCHECKED) EndFunc ;==>YesPressedC Func NoPressedC() $Verify = "" GUICtrlSetState($YesBoxC, $GUI_UNCHECKED) EndFunc ;==>NoPressedC Func CaptureButton() $CapCommand = String("imagex64.exe /capture " & $SelctedDriveLetter & " " & '"' & $CapVar & '"' & " " & '"' & $DescResult & '"' & " " & $Verify) $CheckC = 0 If $SelctedDriveLetter = "0" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No source drive has been selected") $CheckC = 1 EndIf If $CapVar = "0" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No destination file has been selected") $CheckC = 1 EndIf If $DescResult = "0" Then MsgBox(0 + 262144, "Error", "Cannot Continue" & @CRLF & @CRLF & "No image description provided") $CheckC = 1 EndIf If $CheckC = 0 Then While ProcessExists("explorer.exe") ProcessClose("explorer.exe") WEnd Run($CapCommand, "") EndIf EndFunc ;==>CaptureButtonYou were also being very unkind to your CPU, so I added a Sleep(10) in your idle loop to give it a breather. You will notice that I have rearranged the code a bit - I find it much easier if all the GUI creation stuff is not interspersed with Func declarations. Nothing really wrong with the way you had it, but it does make it harder to read in my opinion. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AmbientMike Posted May 15, 2012 Author Share Posted May 15, 2012 (edited) Thanks. So aside from my sloppy coding what was it actually that was forcing it not to render the contents? Just the way the GUI contents were split over the script? Was it the absence of GUICtrlCreateTabItem("") ? I couldn't figure out what that was for... EDIT 2 - I suppose it's the ordering of these 2 commands... GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) Edited May 15, 2012 by AmbientMike Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 AmbientMike, As I said above I imagine it was the absence of the tab structure closing line - in my experience that produces all sorts of weird effects on the tabs and their controls. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AmbientMike Posted May 15, 2012 Author Share Posted May 15, 2012 Thanks. I don't do much of this stuff but some of it is starting to stick in my brain. I am very grateful to you. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 AmbientMike, My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2012 Share Posted May 15, 2012 Thanks. I don't do much of this stuff but some of it is starting to stick in my brain.If you are directed to use some function then always read carefully information about it in AutoIt's helpfile. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now