Jump to content

GUI Not Responding


thefritz
 Share

Go to solution Solved by BrewManNH,

Recommended Posts

So, awhile back, someone else made this tool that helps us load a Sysprepped version of Windows onto our computers.  That person no longer works for us.  Though, right before he left, he created a new version of the script that contains some improvements.  Well, he never tested any of his changes before he left.  We discovered immediatley after he was gone that the tool had a huge bug- one of the buttons in the script was no longer working!  That's fine, we just used the old script for the time being until we had time to get to fixing the new script.  Well, that time is now.  And for the life of me, I cannot figure out why this button stopped working.

The way it works is There is the main window that loads, that windows contains several buttons and menu items.  All of them run different functions in the script.  Everything else, as far as I can tell, works just fine, except for the button we call 'Drivers'.  When you click it, it pops up a window just fine, however, none of the buttons in the window respond to any mouse or keyboard events.  You see the button visually get depressed, but there is no response.  The CPU is pegged (100% for single core machines, ~30% for a quadcore machine) while this stuck GUI is open.

Here is (what I think is) the offending code (this is what is looping according to the AutoIT Debugger using the Step Into button):

$defaultsrcPath='y:\' & $platform & '\' & $model & ' ' & $modelnum & '\x86\Win7\DriverPack'
    $defaultdestPath = 'C:\drivers\computer'
    ;Prompt to make sure directory is correct
    $pathPrompt=GUICreate("Driver Paths", 350, 125)
    $label9=GuiCtrlCreateLabel("Source Path:", 10, 7)
    $srcPathBox=GUICtrlCreateInput($defaultsrcPath, 10, 20, 250, 20)
    $browseSrcBTN= GUICtrlCreateButton("Browse", 270, 20, 40, 20)
    $label10=GuiCtrlCreateLabel("Destination Path:", 10, 50)
    $destPathBox=GUICtrlCreateInput($defaultdestPath, 10, 63, 250, 20)
    $browseDestBTN= GUICtrlCreateButton("Browse", 270, 63, 40, 20)
    $submitBTN=GUICtrlCreateButton("Copy Drivers", 210, 85, 100, 30)
    $driversPath=$defaultsrcPath
    $destPath=$defaultdestPath
    $pathcheck=0
    GUISetState(@SW_SHOW,$pathPrompt)
    While 1
        $pathObj = GUIGetMsg($pathPrompt)
        Select
            Case $pathObj=$browseSrcBTN
                $newsrcpath = FileSelectFolder("Choose Driver Folder", "", "4", "Y:\")
                If NOT($newsrcpath="") Then
                    GUICtrlSetData($srcPathBox, $newsrcpath)
                EndIf
            Case $pathObj=$browseDestBTN
                $newdestpath = FileSelectFolder("Choose Driver Folder", "", "4", "C:\")
                If NOT($newdestpath="") Then
                    GUICtrlSetData($destPathBox, $newdestpath)
                EndIf
            Case $pathObj=$submitBTN
                $driversPath=GUICtrlRead($srcPathBox)
                $destPath=GuiCtrlRead($destPathBox)
                $pathcheck=1
                $pathObj = $GUI_EVENT_CLOSE
        EndSelect
        If $pathObj = $GUI_EVENT_CLOSE Then
            GUISetState(@SW_HIDE,$pathPrompt)
            ExitLoop
        EndIf
    WEnd

Any ideas?

Thanks

Link to comment
Share on other sites

This

$pathObj = GUIGetMsg($pathPrompt)

Should be written like this

$pathObj = GUIGetMsg()

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Post a runnable script so I'm not reinventing what you've already got, and then I'll see what's happening.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

There are multiple files involved.  There is the main Sysprep body (slightly edited to remove sensitive information and to make it run outside my environment.  Edited version tested and still experiencing the problem):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Pictures\icon.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Region Includes
;*****Includes ********
;Includes for Various functions built in to AutoIt.
;Copy.au3 is the reason copying drivers has a progress bar.
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <File.au3>
#include <Constants.au3>
#include <Array.au3>
#include <Copy.au3>
#include <ErrorInterpreter.au3>
#include <Date.au3>
#EndRegion
#region Variables
;Declare Global Variables
Global $FileLocation, $model, $modelnum, $compName, $platform, $userName, $drive, $serviceTag, $logFN
Global $LogDir = ".\LogFiles\Sysprep\" & @Mon & "_" & @MDAY & "_" & @YEAR
Global $defaultBackupFN=$userName & ' ' & $modelnum & ' ' & @MDAY & ' ' & @MON & ' ' & @YEAR & '.TIB'
Global $backupFN
Global $usb_error, $data_error, $backup_error, $migration_error, $diskPart_error, $image_error, $bootrec_error, $driver_error, $hotkey_error, $map_drive_error[3]
Global $Main, $instructionForm, $aboutForm, $filenamePrompt
Global $Main, $backupBTN, $usmtBTN, $gImageXBTN, $diskPrepBTN, $driversBTN, $bootRecBTN
#endregion

;Run setup (Get Service Tag, create log file verify removeable disk)
Setup()

#Region GUI
Opt("GUIOnEventMode", 1)
;************************************Graphical User Interface***********************************************************
;Create Main Window
Global $Main = GuiCreate("FWM Sysprep", 750, 550,-1,-1,-1)
;
;Create Menus in top left corner
;;File Menu Contains:
;;; Ping Check - checks for network connection and reenable buttons if for pingcheck failed.
;;; Open Data File - Opens data file located on flash drive in notepad for editing
;;; Load Data File - Just in case you clicked no at the first prompt, or if you edited the data file you can reload
;;;                 the variables back into the program.
;;; Exit - Exit
    $fileMenu=GuiCtrlCreateMenu("File")
        $dataOpenItem = GuiCtrlCreateMenuItem("Open Data File", $fileMenu)
            GUICtrlSetOnEvent($dataOpenItem, "_Run_Open_DataFile")
        $sysPrepLog=GuiCtrlCreateMenuItem("View SysPrep Log", $fileMenu)
            GUICtrlSetOnEvent($sysPrepLog, "_Log_Sysprep")
        $exitItem=GuiCtrlCreateMenuItem("Exit", $fileMenu)
            GUICtrlSetOnEvent($exitItem, "ExitScript")
;;Utilities Menu:
;;; Command Prompt - Opens a blank command prompt for whatever you need or desire
    $utilsMenu=GuiCtrlCreateMenu("Utilities")
        $cmdItem=GUICtrlCreateMenuItem("Command Prompt", $utilsMenu)
            GUICtrlSetOnEvent($cmdItem, "_Run_CMD")
        $acronisItem=GUICtrlCreateMenuItem("Acronis", $utilsMenu)
            GUICtrlSetOnEvent($acronisItem, "_Run_Acronis")
;;Help Menu:
;;; Instructions - Contains instructions page with tabs to all different functions included in the program
;;; About - Gives version number and such
    $helpMenu=GuiCtrlCreateMenu("Help")
        $instructionsItem=GUICtrlCreateMenuItem("Instructions",$helpMenu)
            GUICtrlSetOnEvent($instructionsItem, "Instructions")
        $aboutItem=GUICtrlCreateMenuItem("About",$helpMenu)
            GUICtrlSetOnEvent($aboutItem, "About")
;
;**Create Main Tabs to Seperate Windows 7 install process and Windows Xp install process**
    GUICtrlCreateTab(0,0,802,602)
;;*Windows 7 Tab:
;;  Contains 6 Buttons - 1 for each process
    $win7Tab = GUICtrlCreateTabItem("Windows 7")
;;; Image at Top - soon to be flash create AVI for splash screen and beauty
    $image1 = GUICtrlCreatePic(".\Pictures\logo.jpg", 0, 40, 750, 315)
;;; Backup Button:
;;;;    Right Click Menu has item for viewing the log file.
    $backupBTN = GUICtrlCreateButton("Backup", 38.5, 400, 80, 80)
        GUICtrlSetOnEvent($backupBTN, "Backup")
        $backupRC = GUICtrlCreateContextMenu($backupBTN)
            $backupLog = GUICtrlCreateMenuItem("View Log", $backupRC)
                GUICtrlSetOnEvent($backupLog, "_Log_Backup")
;;; User State Migration Button:
;;;;    Right Click Menu has items for viewing log file, and for viewing file that list files moved.
    $usmtBTN = GUICtrlCreateButton("USMT", 157, 400, 80, 80)
        GUICtrlSetOnEvent($usmtBTN, "USMT")
        $usmtRC = GUICtrlCreateContextMenu($usmtBTN)
            $usmtLog = GuiCtrlCreateMenuItem("View Log", $usmtRC)
                GUICtrlSetOnEvent($usmtLog, "_Log_USMT")
            $usmtFile = GuiCtrlCreateMenuItem("View Files", $usmtRC)
;;; Disk Prep Button: (Disk Part)
;;;;    Right Click Menu has item to automate disk part, not fully functional yet
;;;;    Also has menu item for viewing log after automation
    $diskPrepBTN = GUICtrlCreateButton("DiskPart", 275.5, 400, 80, 80)
        GUICtrlSetOnEvent($diskPrepBTN, "BackupCheck")
        $diskPrepRC = GUICtrlCreateContextMenu($diskPrepBTN)
            $diskPart = GuiCtrlCreateMenuItem("Disk Part", $diskPrepRC)
                GUICtrlSetOnEvent($diskPart, "_Run_DiskPart")
            $diskPrepLog = GuiCtrlCreateMenuItem("View Log", $diskPrepRC)
                GUICtrlSetOnEvent($diskPrepLog, "_Log_DiskPrep")
;;; GImageX Button:
;;;;    Right Click menu has item to automate process using imagex, not fully functional yet
    $gImageXBTN = GUICtrlCreateButton("GImageX", 394, 400, 80, 80)
        GUICtrlSetOnEvent($gImageXBTN, "BackupCheck")
        $gImageXRC = GUICtrlCreateContextMenu($gImageXBTN)
            $imagex = GuiCtrlCreateMenuItem("Run ImageX x86", $gImageXRC)
                GUICtrlSetOnEvent($imagex, "BackupCheck")
;;; BootRec /rebuild button
    $bootRecBTN = GUICtrlCreateButton("BootRec", 512.5, 400, 80, 80)
        GUICtrlSetOnEvent($bootRecBTN, "_Run_BootRec")
;;; Drivers button
    $driversBTN = GUICtrlCreateButton("Drivers", 631, 400, 80, 80)
        GUICtrlSetOnEvent($driversBTN, "Drivers")
;
;
;;*Windows XP Tab*
;;  Contains 4 Buttons - 1 for each Process
    $winXPTab = GUICtrlCreateTabItem("Windows XP")
;;; Image at Top - soon to be flash create AVI for splash screen and beauty
    $image2 = GUICtrlCreatePic(".\Pictures\logo.jpg", 0, 40, 750, 315)
;;; Backup Button:
;;;;    Right Click Menu has item for viewing the log file.
    $backupBTNxp = GUICtrlCreateButton("Backup", 100, 400, 80, 80)
        GUICtrlSetOnEvent($backupBTNxp, "Backup")
        $backupRCxp = GUICtrlCreateContextMenu($backupBTNxp)
            $backupLogxp = GUICtrlCreateMenuItem("View Log", $backupRCxp)
                GUICtrlSetOnEvent($backupLogxp, "_Log_Backup")
;;; Disk Prep Button: (Disk Part)
;;;;    Right Click Menu has item to automate disk part, not fully functional yet
;;;;    Also has menu item for viewing log after automation
    $diskPrepBTNxp = GuiCtrlCreateButton("DiskPart", 250, 400, 80, 80)
        GUICtrlSetOnEvent($diskPrepBTNxp, "DiskPrep")
        $diskPrepRCxp = GUICtrlCreateContextMenu($diskPrepBTNxp)
            $diskPartxp = GuiCtrlCreateMenuItem("Disk Part", $diskPrepRCxp)
                GUICtrlSetOnEvent($diskPartxp, "_Run_DiskPart")
            $diskPrepLogxp = GuiCtrlCreateMenuItem("View Log", $diskPrepRCxp)
                GUICtrlSetOnEvent($diskPrepLogxp, "_Log_DiskPrep")
;;; GImageX Button:
;;;;    Right Click menu has item to automate process using imagex, not fully functional yet
    $acronisBTNxp = GuiCtrlCreateButton("Acronis", 400, 400, 80, 80)
;;; BootSect /nt52 Button
    $bootsectBTN = GuiCtrlCreateButton("BootSect", 550, 400, 80, 80)
;;;;;;;;;;;;;;;;;;;;;; End Main User Interface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Set Main GUI State
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWindow")
GUISwitch($Main)
GuiSetState(@SW_SHOW,$Main)
While 1
    Sleep(1000)
WEnd
#endregion
#region Setup
Func Setup()
    ;Get service tag for INI file
    $getServiceTag = Run(@COMSPEC & ' /c' & 'wmic csproduct get identifyingNumber', @SYSTEMDIR, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Sleep(1000)
    $output = StdoutRead($getServiceTag)
    $output = StringStripWS($output, 4) ;STrip of unecessary spaces between words
    $outputarray=StringSplit($output, " ")
    $serviceTag=$outputarray[2]
    _Ping()
    If FileExists("W:\sysinfo\data.ini") Then
        $FileLocation = "W:\sysinfo\data.ini"
    Else
        $FileLocation = @SystemDir & "\data.ini"
        IniWriteSection($FileLocation, $serviceTag, "Model=Test" & @LF & "Modelnum=Test" & @LF & "CompName=Test" & @LF & "Username=Test" & @LF)
    EndIf
    ;Create Log File and put title and date on it.
    Local $defaultlogFN=$serviceTag & "_sysprepLog.txt"
    DirCreate($LogDir)
    If FileExists($LogDir & "\" & $defaultlogFN) Then
        For $c = 1 to 25
            If FileExists($LogDir & "\" & $serviceTag & "_sysprepLog" & $c & ".txt") Then
                ;Do not create File
            Else
                $logFN = $LogDir & "\" & $serviceTag & "_sysprepLog" & $c & ".txt"
                $logFile = FileOpen($logFN, 2)
                ExitLoop
            EndIf
        Next
    Else
        $logFN = $LogDir & "\" & $defaultlogFN
        $logFile = FileOpen($logFN,2)
    EndIf
    FileWriteLine($logFile, "Fort Wayne Metals - System Preparation Utitlity")
    FileWriteLine($logFile, @Mon & "/" & @MDAY & "/" & @YEAR & " @ " & _NowTime())
    FileClose($logfile)
    GetData()
EndFunc
#endregion
#Region Ping
;Checks for network connection
Func _Ping()
;;  Pings ITServ for network connection since files are located on it.
;   $ping = Ping("<server>")
;   $ping_error = @error
;;; If Successful ping then maps drives, else disables buttons.
;   If $ping > 0 Then
;       $ping_error = _Interpreter('Ping', 0)
;
;       $mapDrive = DriveMapAdd('U:', '<mapped drive path>', 0, '<account>', '<password>')
;       If $mapDrive = 0 Then
;           $map_drive_error[0]=_Interpreter('Map',@error, 'U:')
;       Else
;           $map_drive_error[0]=_Interpreter('Map',0, 'U:')
;       EndIf
;       $mapDrive = DriveMapAdd('W:', '<mapped drive path>', 0, '<account>', '<password>')
;       If $mapDrive = 0 Then
;           $map_drive_error[1]=_Interpreter('Map',@error, 'W:')
;       Else
;           $map_drive_error[1]=_Interpreter('Map',0, 'W:')
;       EndIf
;       $mapDrive = DriveMapAdd('Y:', '<mapped drive path>', 0, '<account>', '<password>')
;       If $mapDrive = 0 Then
;           $map_drive_error[2]=_Interpreter('Map',@error, 'Y:')
;       Else
;           $map_drive_error[2]=_Interpreter('Map',0, 'Y:')
;       EndIf
;       If ($map_drive_error[0] + $map_drive_error[1] + $map_drive_error[2]) > 0 Then
;           Run("map.bat", @SYSTEMDIR)
;       EndIf
        BTNswitchOn()
;   Else
;       BTNswitchOff()
;       $ping_error = _Interpreter('Ping', $ping_error)
;   EndIf
EndFunc
#endregion
#region Data
Func GetData()
    ; Custom Prompt asking if you even need a data file. IF you do, you also have the option of using the current one, if one is found on the usb drive.
    $useDataFilebox = GuiCreate("Data File", 300, 100)
    $usedatafileLabel = GUICtrlCreateLabel("Is this an upgrade?", 15, 15)
    $checkbox1 = GUICtrlCreateCheckbox("Use Data.ini", 115, 11)
    $yesButton = GUICtrlCreateButton("Yes", 160, 60, 50, 25)
    $noButton = GUICtrlCreateButton("No", 225, 60, 50, 25)
    GUISetState(@SW_SHOW, $useDataFilebox)
    GUICtrlSetState($checkbox1, $GUI_CHECKED)
    While 1
        $use = GUIGetMsg($useDataFilebox)
        Select
            Case $use = $yesButton
                GUISetState(@SW_HIDE, $useDataFilebox)
                If FileExists("C:\Programs.txt") Then
                    FileCopy("C:\Programs.txt", "X:\")
                EndIf
                If FileExists("C:\Printers.txt") Then
                    FileCopy("C:\Printers.txt", "X:\")
                EndIf
                If GuiCtrlRead($checkbox1) = $GUI_CHECKED Then
                    ReadData()
                Else
                    GetModel()
                    MakeData()
                EndIf
                $use = $GUI_EVENT_CLOSE
            Case $use = $noButton
                GUISetState(@SW_HIDE, $useDataFilebox)
                GetModel()
                $userName = "(username)"
                $compName = "(compName)"
                $use = $GUI_EVENT_CLOSE
                $data_error = _Interpreter('Data', 2)
        EndSelect
        If $use = $GUI_EVENT_CLOSE Then
            GUISetState(@SW_HIDE, $useDataFilebox)
            ExitLoop
        EndIf
    WEnd
EndFunc
Func GetModel()
    $getModel = Run(@COMSPEC & ' /c' & 'wmic computersystem get model', @SYSTEMDIR, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Sleep(1000)
    $output = StdoutRead($getModel)
    $output = StringStripWS($output, 4) ;STrip of unecessary spaces between words
    $outputarray=StringSplit($output, " ")
    For $x = 0 to $outputarray[0]
        If StringInStr($outputarray[$x], "Latitude") Then
            $model = $outputarray[$x]
            $modelnum = $outputarray[$x + 1]
            $platform = "Laptop"
            ExitLoop
        ElseIf StringInStr($outputarray[$x], "Optiplex") Then
            $model = $outputarray[$x]
            $modelnum = $outputarray[$x + 1]
            $platform = "Desktop"
            ExitLoop
        EndIf
    Next
EndFunc
Func MakeData()
    $infoForm = GuiCreate("SysPrep", 300, 120)
    $labelComp = GUICtrlCreateLabel("Old Computer Name", 15, 10)
    $compNameBox = GUICtrlCreateInput("", 15, 25, 125, 25)
    $labelUser = GUICtrlCreateLabel("UserName", 155, 10)
    $userNameBox = GUICtrlCreateInput("", 155, 25, 125, 25)
    $SubmitBTN = GUICtrlCreateButton("Submit", 140, 80, 50, 25)
    GUISetState(@SW_SHOW,$infoForm)
    While 1
        $info = GUIGetMsg($infoForm)
        Select
            Case $info = $SubmitBTN
                GUISetState(@SW_HIDE,$infoForm)
                $compName=GuiCtrlRead($compNameBox)
                $userName=GuiCtrlRead($userNameBox)
                If $compName = "" then
                    MakeData()
                ElseIf $userName = "" then
                    MakeData()
                Else
                    $keys="Model=" & $model & @LF & "Modelnum=" & $modelnum & @LF & "CompName=" & $compName & @LF & "UserName=" & $userName & @LF
                    IniWriteSection($FileLocation, $serviceTag, $keys)
                EndIf
            ExitLoop
        EndSelect
    WEnd
EndFunc
Func ReadData()
    $model=IniRead($FileLocation, $serviceTag, "Model", $model)
    $modelnum=IniRead($FileLocation, $serviceTag, "Modelnum", $modelnum)
    $compName=IniRead($FileLocation, $serviceTag, "CompName", "(computer)")
    $userName=IniRead($FileLocation, $serviceTag, "UserName", "(username)")
    If StringInStr($model, "Latitude") Then
        $platform = "Laptop"
    ElseIf StringInStr($model, "Optiplex") Then
        $platform = "Desktop"
    EndIf
    IF $userName = "newuser" Then
        $data_error = _Interpreter('Data', 1)
    Else
        $data_error = _Interpreter('Data', 0)
    EndIf
EndFunc
#endregion Setup
#Region Backup
Func Backup()
    ;GUI For Filename Prompt
    Opt("GUIOnEventMode", 1)
    Global $filenamePrompt=GUICreate("Backup Filename", 350, 120)
    $label12=GUICtrlCreateLabel("What do you want the backup file to be called. Default naming" & @CRLF & "convention is shown in textbox.", 10, 10)
    $label11=GuiCtrlCreateLabel("Filename:", 10, 37)
    Global $filenameBox=GUICtrlCreateInput($defaultBackupFN, 10, 50, 250, 20)
    $submitBTN=GUICtrlCreateButton("Submit", 210, 80, 100, 30)
        GUICtrlSetOnEvent($submitBTN, "_Run_Backup")
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWindow")
    GUISwitch($filenamePrompt)
    GUISetState(@SW_SHOW, $filenamePrompt)
EndFunc
Func _Run_Backup()
    $backupFN=GUICtrlRead($filenameBox)
    GUISetState(@SW_HIDE, $filenamePrompt)

    $listPartitions = Run(@COMSPEC & ' /c' & 'TrueImageCmd.exe /list', @ProgramFilesDir & '\Acronis\BackupAndRecovery\', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Sleep(5000)
    $output = StdoutRead($listPartitions)
    $output = StringStripCR($output)
    $outputarray=StringSplit($output, @CRLF)
    $c = 0
    $line = "Line"                              ; = the line that display the C: drive in the /list command by acronis
    For $x = 0 to $outputarray[0]
        If StringInStr($outputarray[$x], "C:") Then
            $line = $outputarray[$x]
            $newarray = StringSplit($line, " ")
            $partition = $newarray[1]
            StringStripWS($partition,8)
            $c = $c +1
        EndIf
    Next
    If $partition = "" Then
        $backup_error = _Interpreter('Backup', 1)
    ElseIf $partition = "null" Then
        $backup_error = _Interpreter('Backup', 3)
    ElseIf StringInStr($line, $partition) = 0 Then
        $backup_error = _Interpreter('Backup', 2)
    Else
        $AcronisCMD = 'TrueImageCmd.exe /create /partition:' & $partition & ' /progress:on /compression:9 /filename:"U:\' & $backupFN & '" /log:' & @SystemDir & '\LogFiles\backup.log'
        Run(@COMSPEC & ' /k' & $AcronisCMD, @ProgramFilesDir & '\Acronis\BackupAndRecovery\')
        $backup_error = _Interpreter('Backup', 0)
    EndIf
EndFunc
#endregion Backup
#Region User State Migration
Func USMT()
    $random = Random(1111, 9999)
    $tempDir = "Temp" & $random
    $migrationFolder = 'U:\USMT\Migration\' & $compName
    $migrationXML = 'usermigrate.xml'
    $setWorkDirCMD = 'SET USMT_WORKING_DIR=U:\USMT\' & $tempDir
    $scanstateCMD = 'scanstate.exe ' & $migrationFolder & ' /offlineWinDir:C:\Windows /i:' & $migrationXML & ' /ui:FWMRPC\' & $userName & ' /ue:' & $compName & '\* /ue:FWMRPC\Administrator /ue:FWMRPC\fwmetals /v:13 /L:' & @SystemDir & '\LogFiles\scanstate.log /listfiles:' & @SystemDir & '\LogFiles\Files.txt  /c /o'
    Run(@COMSPEC & ' /k' & $setWorkDirCMD & "&&" & $scanstateCMD, @ProgramFilesDir & '\USMT4.01\')
    $migration_error = _Interpreter('USMT', 0)
EndFunc
#EndRegion USMT
#Region Disk Prepartion
Func BackupCheck()
    If FileExists($drive & "\Backups\" & $backupFN) Then
        $size = FileGetSize($drive & "\Backups\" & $backupFN)
        If ($size/1048576) < 3072 Then
            $check = MsgBox(4, "Warning: Backup", "Your backup file is quite small. This can be caused by failed backup due to interruption or corruption. It is highly recommended that you rerun the backup process, however you may continue at your own risk. Continue?")
            If $check = 6 Then
                If @GUI_CTRLID = $diskPrepBTN Then
                    _Run_AutomatedDiskPrep()
                ElseIf @GUI_CTRLID = $GImageXBTN Then
                    _Run_GImageX()
                ElseIf @GUI_CTRLID = $imagex Then
                    _Run_ImageX()
                EndIf
            Endif
        Else
            $backup_check = MsgBox(4, "System Check: Backup", "Have you ran a backup yet? If not, please do so before wiping the disk.")
            If $backup_check = 6 Then
                If @GUI_CTRLID = $diskPrepBTN Then
                    _Run_AutomatedDiskPrep()
                ElseIf @GUI_CTRLID = $GImageXBTN Then
                    _Run_GImageX()
                ElseIf @GUI_CTRLID = $imagex Then
                    _Run_ImageX()
                EndIf
            Else
                MsgBox(0, "Abort!", "Run backup before proceeding!")
            EndIf
        EndIf
    Else
        If FileExists($drive & "\Backups\" & $defaultBackupFN) Then
            $size = FileGetSize($drive & "\Backups\" & $backupFN)
            If ($size/1048576) < 3072 Then
                $check = MsgBox(4, "Warning: Backup", "Your backup file is quite small. This can be caused by failed backup due to interruption or corruption. It is highly recommended that you rerun the backup process, however you may continue at your own risk. Continue?")
                If $check = 6 Then
                    If @GUI_CTRLID = $diskPrepBTN Then
                    _Run_AutomatedDiskPrep()
                    ElseIf @GUI_CTRLID = $GImageXBTN Then
                        _Run_GImageX()
                    ElseIf @GUI_CTRLID = $imagex Then
                        _Run_ImageX()
                    EndIf
                Endif
            Else
                $backup_check = MsgBox(4, "System Check: Backup", "Have you ran a backup yet? If not, please do so before wiping the disk.")
                If $backup_check = 6 Then
                    If @GUI_CTRLID = $diskPrepBTN Then
                    _Run_AutomatedDiskPrep()
                    ElseIf @GUI_CTRLID = $GImageXBTN Then
                        _Run_GImageX()
                    ElseIf @GUI_CTRLID = $imagex Then
                        _Run_ImageX()
                    EndIf
                Else
                    MsgBox(0, "Abort!", "Run backup before proceeding!")
                EndIf
            EndIf
        Else
            $check= MsgBox(4, "System: Missing Backup", "No backup file found. Please run the backup process to ensure no loss of data. However you may continue at your risk. Continue?")
            If $check = 6 Then
                If @GUI_CTRLID = $diskPrepBTN Then
                    _Run_AutomatedDiskPrep()
                ElseIf @GUI_CTRLID = $GImageXBTN Then
                    _Run_GImageX()
                ElseIf @GUI_CTRLID = $imagex Then
                    _Run_ImageX()
                EndIf
            Else
                MsgBox(0, "Abort!", "Run backup before proceeding!")
            EndIf
        EndIf
    EndIf
EndFunc
Func _Run_AutomatedDiskPrep()
    $listPartitions = Run(@COMSPEC & ' /c' & 'TrueImageCmd.exe /list', @ProgramFilesDir & '\Acronis\BackupAndRecovery\', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Sleep(6000)
    $output = StdoutRead($listPartitions)
    If $output = "" Then
        $diskPart_error = _Interpreter('DiskPart', 1)
        MsgBox(0, "Error: Operation Aborted!", "Automation Error, operation aborted. View Log File for more information.")
    Else
        $output = StringStripCR($output)
        $outputarray=StringSplit($output, @CRLF)
        $line = "Line"
        $partitionAmount = 0
        $diskNumber = 1
        For $x = 0 to $outputarray[0]
            If StringInStr($outputarray[$x], "C:") Then
                    $line = $outputarray[$x]
                    $diskNumber = StringLeft($line, 1)
            EndIf
        Next
        If $line = "" Then
            $diskPart_error = _Interpreter('DiskPart', 2)
            MsgBox(0, "Error: Aborted!", "Automation Error, operation aborted. View Log File for more information.")
        Else
            For $x = 0 to $outputarray[0]
                If StringInStr($outputarray[$x], $diskNumber & "-") Then
                    $partitionAmount = $partitionAmount + 1
                EndIf
            Next
            $AutoFile = FileOpen(@SystemDir & "\auto.txt", 2)
            $error = 0
            If $partitionAmount = 0 Then
            FileWriteLine($AutoFile, "Select Disk 0")
            Else
                For $x = 1 to $partitionAmount
                    If StringInStr($line, $diskNumber & "-" & $x) Then
                        FileWriteLine($AutoFile, "Select Disk " & ($diskNumber - 1))
                        FileWriteLine($AutoFile, "Select Partition " & $x)
                        FileWriteLine($AutoFile, "Delete Partition")
                        If $partitionAmount > 2 Then
                            For $i = 2 to $partitionAmount
                                If StringInStr($line, $diskNumber & "-" & $i) Then
                                    ;Do Nothing
                                Else
                                    FileWriteLine($AutoFile, "Select Partition " & $i)
                                    FileWriteLine($AutoFile, "Delete Partition")
                                EndIf
                            Next
                        EndIf
                        $error = 0
                    Else
                        $error = $error + 1
                        If $error = $partitionAmount Then
                            $error = 3
                        Else
                            $error = 0
                        EndIf
                    EndIf
                Next
            EndIf
        EndIf
        IF $error = 0 Then
            FileWriteLine($AutoFile, "Create Partition Primary")
            FileWriteLine($AutoFile, "Format FS=NTFS Quick")
            FileWriteLine($AutoFile, "Active")
            FileWriteLine($AutoFile, "Assign letter=C")
            FileClose($AutoFile)
            Runwait(@COMSPEC & ' /c' & 'diskpart /s ' & @SystemDir & '\auto.txt > ' & @SystemDir & 'log.txt', @SystemDir)
            $diskPart_error = _Interpreter('DiskPart', 0)
            MsgBox(0, "Success!", "Disk Part successfully prepared the drive.")
        Else
            $diskPart_error = _Interpreter('DiskPart', 3)
        EndIf
    EndIf
EndFunc
Func _Run_DiskPart()
    Run(@COMSPEC & ' /c' & 'diskpart', @SystemDir)
    _Interpreter('DiskPart', 0)
EndFunc
#endregion Disk Preparation
#Region ImageX
Func _Run_GImageX()
    Run('GImageX86.exe')
    $image_error = _Interpreter('Image', 0)
EndFunc
Func _Run_ImageX()
    $imageFile = "'W:\Win7\Current\Sysprep Win7 Ent 1d x86.wim'"
    Run(@comspec & ' /k imagex.exe /apply "' & $imageFile & '" 1 C:\')
    $image_error = _Interpreter('Image', 0)
EndFunc
#endregion ImageX
#region Boot Record
Func _Run_BootRec()
    Run(@COMSPEC & ' /k' & 'bootrec /rebuildbcd', @SystemDir)
    $bootRec_error = _Interpreter('Boot', 0)
EndFunc
Func _Run_BootSect()
    Run(@COMSPEC & ' /k' & 'bootsect /nt52 sys', @SystemDir)
    $bootRec_error = _Interpreter('Boot', 0)
EndFunc
#endregion Boot Record
#Region Drivers
Func Drivers()
    $defaultsrcPath='y:\' & $platform & '\' & $model & ' ' & $modelnum & '\x86\Win7\DriverPack'
    $defaultdestPath = 'C:\drivers\computer'
    ;Prompt to make sure directory is correct
    $pathPrompt=GUICreate("Driver Paths", 350, 125)
    $label9=GuiCtrlCreateLabel("Source Path:", 10, 7)
    $srcPathBox=GUICtrlCreateInput($defaultsrcPath, 10, 20, 250, 20)
    $browseSrcBTN= GUICtrlCreateButton("Browse", 270, 20, 40, 20)
    $label10=GuiCtrlCreateLabel("Destination Path:", 10, 50)
    $destPathBox=GUICtrlCreateInput($defaultdestPath, 10, 63, 250, 20)
    $browseDestBTN= GUICtrlCreateButton("Browse", 270, 63, 40, 20)
    $submitBTN=GUICtrlCreateButton("Copy Drivers", 210, 85, 100, 30)
    $driversPath=$defaultsrcPath
    $destPath=$defaultdestPath
    $pathcheck=0
    GUISetState(@SW_SHOW,$pathPrompt)
    While 1
        $pathObj = GUIGetMsg($pathPrompt)
        Select
            Case $pathObj=$browseSrcBTN
                $newsrcpath = FileSelectFolder("Choose Driver Folder", "", "4", "Y:\")
                If NOT($newsrcpath="") Then
                    GUICtrlSetData($srcPathBox, $newsrcpath)
                EndIf
            Case $pathObj=$browseDestBTN
                $newdestpath = FileSelectFolder("Choose Driver Folder", "", "4", "C:\")
                If NOT($newdestpath="") Then
                    GUICtrlSetData($destPathBox, $newdestpath)
                EndIf
            Case $pathObj=$submitBTN
                $driversPath=GUICtrlRead($srcPathBox)
                $destPath=GuiCtrlRead($destPathBox)
                $pathcheck=1
                $pathObj = $GUI_EVENT_CLOSE
        EndSelect
        If $pathObj = $GUI_EVENT_CLOSE Then
            GUISetState(@SW_HIDE,$pathPrompt)
            ExitLoop
        EndIf
    WEnd

    If $pathcheck>0 Then
        DirCreate($destPath)
        If Not _Copy_OpenDll() Then
            MsgBox(16, '', 'DLL not found.')
            $driver_error = _Interpreter('Driver', 1)
        Else
            $destPathSize = DirGetSize($destPath)
            If $destPathSize > 0 Then
                $driverSize = DirGetSize($driversPath)
                If $destPathsize < $driverSize Then
                    $internal_dir_error = 4;Drivers not copied correctly (greater or smaller)
                Else
                    $internal_dir_error = 5 ;Drivers already copied
                EndIf
            EndIf
            If $driversStatus = 0 Then
                CopyDrivers($driversPath, $destPath)
                $driver_error = _Interpreter('Driver', 0)
                Return 1
            ElseIf $driversStatus = 1 Then
                If $internal_dir_error = 4 Then
                    DirRemove($destPath)
                    DirCreate($destPath)
                    CopyDrivers($driversPath, $destPath)
                    $driver_error = _Interpreter('Driver', 0)
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc
Func CopyDrivers($source,$dest)
    Local $Copy = False
    $progressBox = GuiCreate("Copying Files...", 400, 150)
    $fromLabel = GUICtrlCreateLabel("Copying Files from " & $source & " ...", 20, 30, 360, 20)
    $Progress = GUICtrlCreateProgress(20, 50, 360, 20)
    $percentComplete = GUICtrlCreateLabel("0% Complete", 20, 75, 360, 20)
    GUISetState(@SW_SHOW, $progressBox)
    _Copy_CopyDir($source,$dest)
    $Copy = 1
    While 1
        $msg2 = GUIGetMsg($progressBox)
        If $Copy Then
            $State = _Copy_GetState()
            If $State[0] Then
                $Data = Round($State[1] / $State[2] * 100)
                If GUICtrlRead($Progress) <> $Data Then
                    GUICtrlSetData($Progress, $Data)
                    GuiCtrlSetData($percentComplete, $Data & "% Complete")
                EndIf
            Else
                Switch $State[5]
                    Case 0
                        GUICtrlSetData($Progress, 100)
                        MsgBox(64, '', 'Files were successfully copied.', 0, $progressBox)
                        $driversStatus = 0
                        $msg2 = $GUI_EVENT_CLOSE
                    Case 1235 ; ERROR_REQUEST_ABORTED
                        MsgBox(16, '', 'File copying was aborted.', 0, $progressBox)
                        $driversStatus = 1235
                        $msg2 = $GUI_EVENT_CLOSE
                    Case Else
                        MsgBox(16, '', 'File was not copied.' & @CR & @CR & $State[5], 0, $progressBox)
                        $driversStatus = 500
                        $msg2 = $GUI_EVENT_CLOSE
                EndSwitch
                GUICtrlSetData($Progress, 0)
                GuiCtrlSetData($percentComplete, $Data & "% Complete")
                $Copy = 0
            EndIf
        EndIf
        Select
            Case $msg2 = $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE, $progressBox)
                _Copy_Abort()
                ExitLoop
        EndSelect
    WEnd
    Return $driversStatus
EndFunc
#Endregion Drivers
#Region Random Small Functions
Func _Run_CMD()
    Run("cmd.exe", @SystemDir)
EndFunc
Func _Run_Acronis()
    Run(@ProgramFilesDir & "\Acronis\BackupAndRecovery\TrueImage.exe")
EndFunc
Func _Run_Open_DataFile()
    Run("notepad.exe " & $drive & "\sysinfo\data.ini")
EndFunc
Func BTNswitchOff()
        GUICtrlSetState($backupBTN,$GUI_DISABLE)
        GUICtrlSetState($usmtBTN,$GUI_DISABLE)
        GUICtrlSetState($gImageXBTN,$GUI_DISABLE)
        GUICtrlSetState($diskPrepBTN,$GUI_DISABLE)
        GUICtrlSetState($driversBTN,$GUI_DISABLE)
        GUICtrlSetState($bootRecBTN,$GUI_DISABLE)
EndFunc
Func BTNswitchOn()
        GUICtrlSetState($backupBTN, $GUI_ENABLE)
        GUICtrlSetState($usmtBTN, $GUI_ENABLE)
        GUICtrlSetState($gImageXBTN, $GUI_ENABLE)
        GUICtrlSetState($diskPrepBTN, $GUI_ENABLE)
        GUICtrlSetState($driversBTN, $GUI_ENABLE)
        GUICtrlSetState($bootRecBTN, $GUI_ENABLE)
EndFunc
Func HotKeyPress()
        GUICtrlSetState($backupBTN, $GUI_ENABLE)
        GUICtrlSetState($usmtBTN, $GUI_ENABLE)
        GUICtrlSetState($gImageXBTN, $GUI_ENABLE)
        GUICtrlSetState($diskPrepBTN, $GUI_ENABLE)
        GUICtrlSetState($driversBTN, $GUI_ENABLE)
        GUICtrlSetState($bootRecBTN, $GUI_ENABLE)
        $hotkey_error = _Interpreter('Hotkey', 1)
EndFunc
#endregion
#Region Log Files
Func _Log_Sysprep()
    Run(@COMSPEC & ' /c' & $file, @SystemDir, @SW_HIDE)
EndFunc
Func _Log_Backup()
    Run(@COMSPEC & ' /c' & '.\LogFiles\backup.log', @SystemDir, @SW_HIDE)
EndFunc
Func _Log_USMT()
    Run(@COMSPEC & ' /c' & '.\LogFiles\scanstate.log', @SystemDir, @SW_HIDE)
EndFunc
#endregion
#Region Instruction Page
Func Instructions()
    Opt("GUIOnEventMode", 1)
    $instructionForm = GuiCreate("FWM SysPrep - Instructions", 700, 500)
        GUICtrlCreateTab(0,0,702, 502)
        $programTab = GUICtrlCreateTabItem("Sysprep")
            $title1 = GUICtrlCreateLabel("Sysprep Process", 7, 30)
            $description1 = GuiCtrlCreateLabel("Windows 7 Process:" & @CRLF & _                                                                                 ; Can only come this far
                                               "    1. Backup - (For Upgrades from XP) Acronis TruImageCMD.exe. Backs up the hard drive in a viewable format. " & @CRLF & _
                                               "    2. USMT - (For Upgrades from XP) User State migration Tool. Copies all personal files in user directories plus " & @CRLF & _
                                               "       .pst files and .nk2 files. After upgrade USMT copies these files to coresponding directories." & @CRLF & _
                                               "    3. DiskPart - Windows command line utility for formatting and partitioning hard drive." & @CRLF & _
                                               "    4. GImageX - GUI version of ImageX used to extract the Windows 7 WIM file onto the hard drive." & @CRLF & _
                                               "    5. BootRec - The /rebuildbcd parameter rebuilds the boot manager on the hard drive to point toward our new" & @CRLF & _
                                               "       image on the C: drive." & @CRLF & _
                                               "    6. Drivers - Copies drivers from Fileserv2 to specified area on new Windows install." & @CRLF & _
                                               " "  & @CRLF & _
                                               "Windows XP Process:"  & @CRLF & _
                                               "    1. Backup - Same as above"  & @CRLF & _
                                               "    2. Used to reformat and partition hard drive for new install of XP."  & @CRLF & _
                                               "    3. GImageX - Used to extract XP image to computer." & @CRLF & _
                                               " ", 7, 50, 683, 500)

        $programTab2 = GUICtrlCreateTabItem("Sysprep Con't")
            $title2 = GuiCtrlCreateLabel("Things to Know", 7, 30)
            $description2 = GuiCtrlCreateLabel("FAQs:" & @CRLF & _
                                               "Question: My buttons are disabled how to I re-enable them?"  & @CRLF & _
                                               "Answer: If your buttons are disabled it is because you do not have a connection to Fileser2. To re-enable" & @CRLF & _
                                               "     the buttons you have to either extablish a connection to Fileserv2 and re-run the pingcheck or you" & @CRLF & _
                                               "    can use the HotKey (Ctrl + Alt + M) to manually override your network connection status and enable" & @CRLF & _
                                               "    the buttons. I suggest establishing a connection since most utilities push or pull data from Fileserv2"  & @CRLF & _
                                               "    however, if you are using this jsut as a utility to run commands go right ahead and override them." & @CRLF & _
                                               " " & @CRLF & _
                                               "Question: What is the Data.txt file? And what data resides in it?" & @CRLF & _
                                               "Answer: The data.txt file is located on the root of the thumbdrive you are using. This file is used to store" & @CRLF & _
                                               "    information about the current system such as the model type and number. The format of the text file is" & @CRLF & _
                                               "    the following." & @CRLF & _
                                               "        1. Model - Such as Optiplex or Latitude" & @CRLF & _
                                               "        2. Model Number - Such as 990, 780, gx520, or E6400"  & @CRLF & _
                                               "        3. ComputerName - (On new installs defualt is NEWPC1)" & @CRLF & _
                                               "        4. UserName - (On new installs default is newuser)"  & @CRLF & _
                                               "    These lines are loaded into variables and put into different commands throughout the script. The data file" & @CRLF & _
                                               "    could have been made when you ran PreSysPrep.exe on an upgrade machine, or manually when running this " & @CRLF & _
                                               "    script. If you forgot to run the PreSysPrep.exe script on an upgrade machine this script will allow " & @CRLF & _
                                               "    you to add the computername and username to the data file."  & @CRLF & _
                                               " ", 10, 50, 683, 500)
        $backupTab = GUICtrlCreateTabItem("Backup")
            $title3 = GUICtrlCreateLabel("Backup Process", 10, 30)
            $description3 = GuiCtrlCreateLabel("Uses TrueImageCMD.exe, a command line utility provided by Acronis."  & @CRLF & _
                                               " "  & @CRLF & _
                                               "    After clicking the button you are prompted for the partition number in #-# notation. The input box should list"  & @CRLF & _
                                               "the current drive number - partition number that the C: drive is on. You should verify that this number is the same" & @CRLF & _
                                               "as the number in the input box. If it is not the same please change the number to the correct number in the correct" & @CRLF & _
                                               "#-# notation as noted." & @CRLF & _
                                               "    If the inputbox does not show the current drive number - partition number of the C: drive then you will need to" & @CRLF & _
                                               "verify it manually. To do this open up an command prompt and navigate to " & @ProgramFilesDir & "\Acronis\BackupAndRecovery\" & @CRLF & _
                                               "directory. Once you are in this directory run the following command to view the current drives and parition on the " & @CRLF & _
                                               "machine and verify which one is the C: drive. After you have submitted the correct drive the a command window will open"  & @CRLF & _
                                               "and begin the backup process. If the command fails for any reason you can manually enter it using the following command:" & @CRLF & _
                                               " " & @CRLF & _
                                               " ", 10, 50, 683)
            $command1 = GUICtrlCreateInput('TrueImageCmd.exe /create /partition:(#-#) /progress:on /compression:9 /filename:"U:\'& $userName & ' ' & $modelnum & ' ' & @MDAY & ' ' & @MON & ' ' & @YEAR & '.TIB" /log:' & @SystemDir & '\LogFiles\backup.log', 10, 250, 680, 20)
        $usmtTab = GUICtrlCreateTabItem("USMT")
            $title4 = GUICtrlCreateLabel("USMT Process", 10, 30)
            $description4 = GUICtrlCreateLabel("Uses Scanstate.exe in the User State Migration Tool 4.01, provided by Microsoft." & @CRLF & _
                                               " " & @CRLF & _
                                               "    After Clicking the button you are prompted to enter in a name for the temporary working directory. The User State Migration Tool" & @CRLF & _
                                               "needs a working directory for temporary files while it is migrating data from the computer. You can leave the default if you like but"& @CRLF & _
                                               "sometimes it fails, so don't be afraid to switch it up. Note this folder does get deleted right after the process complete so do not" & @CRLF & _
                                               "name it after the computer name or user name." & @CRLF & _
                                               "    If the command fails you can manually enter it. To do this you must be in the " & @ProgramFilesDir & "\USMT4.01\ directory. After" & @CRLF & _
                                               "you are in this directory you must set the temporary working directory using the first command shown below. After you have set the" & @CRLF & _
                                               "working directory you can then run the Scanstate command listed below."& @CRLF & _
                                               "    Whether you manually entered it or it ran right away the command will generate a log file you can view as well as a file with a list "& @CRLF & _
                                               "of the files it migrated. Notice these files will not remain on the thumbdrive and will be deleted after you exit. So if you want to keep" & @CRLF & _
                                               "the files pull up a command prompt and use xcopy or copy to copy the files to your destination. I may add a button to do it later." & @CRLF & _
                                               " "& @CRLF & _
                                               " ",10, 50, 683)
            $command2 = GUICtrlCreateInput("SET USMT_WORKING_DIR=U:\USMT\Temporary", 10, 250, 683, 20)
            $command3 = GUICtrlCreateInput('scanstate.exe U:\Migration\' & $compName & ' /offlineWinDir:C:\Windows /i:usermigrate.xml /ui:FWMRPC\' & $userName & ' /ue:' & $compName & '\* /ue:FWMRPC\Administrator /ue:FWMRPC\fwmetals /v:13 /L:' & @SystemDir & '\LogFiles\scanstate.log /listfiles:' & @SystemDir & '\LogFiles\Files.txt  /c /o', 10, 280, 683, 20)
        $diskPartTab = GUICtrlCreateTabItem("DiskPart")
            $title5 = GuiCtrlCreateLabel("DiskPart Process", 10, 30)
            $description5 = GUICtrlCreateLabel("Uses Disk Part utility by Microsoft." & @CRLF & _
                                               " " & @CRLF & _
                                               "    After clicking the button Disk Part is launched. For upgrades you will delete the primary partition and then create a new primary partition." & @CRLF & _
                                               " For a new computer do delete all partitions except the Dell OEM partition. These are the commands you need to know to create, delete, and partition a drive." & @CRLF & _
                                               "        1. List Disk - list the disks curently on the machine." & @CRLF & _
                                               "        2. Select Disk - Selects the disk you want to work on." & @CRLF & _
                                               "        3. List Partition - list the partitions on the currently selected disk." & @CRLF & _
                                               "        4. Select Partition - selects the parition you want to work on. " & @CRLF & _
                                               "        5. Delete Partition - deletes the selected partition." & @CRLF & _
                                               "        6. Create Partition Primary - creates a primary partition. And selects this partition to work on." & @CRLF & _
                                               "        7. Format FS=NTFS Quick - formats the selected partition to NTFS using the quick way. Do NOT forget the QUICK command." & @CRLF & _
                                               "        8. Active - marks the partition as active." & @CRLF & _
                                               "        9. Assign (Optional: Letter = C) - Assign a drive letter. Will need to be drive C so if it does not set to C by default you can" & @CRLF & _
                                               "           change the drive letter using the letter command." & @CRLF & _
                                               "        10. List Volume - list the volumes on the machine, which shows drive letter, size, name, and partition format." & @CRLF & _
                                               "    Optional Commands:" & @CRLF & _
                                               "        Clean - cleans the drive of all partitions. Only use on drives that do not have the Dell OEM partition." & @CRLF & _
                                               "    You can also right click and hit Automate DiskPart and it does the process for you. However if you have already clicked the" & @CRLF & _
                                               "    normal DiskPart button it won't allow you to because DiskPart has been ran once already." & @CRLF & _
                                               " " & @CRLF & _
                                               " ", 10, 45, 683)
        $gimageXTab = GuiCtrlCreateTabItem("GImageX")
            $title6 = GuiCtrlCreateLabel("GImageX86 Process", 10, 30)
            $description6 = GUICtrlCreateLabel("Uses GImageX86.exe, the graphical utility to ImageX." & @CRLF & _
                                               " " & @CRLF & _
                                               "    After clicking the button GImageX86 is launched. In GImageX go to the apply tab. In this tab select the source directory using the browse"  & @CRLF & _
                                               "button and select W:\Win7\ or W:\WinXP\ and then the proper image. Then select the destination directory using the browse button and click" & @CRLF & _
                                               "on the C:\ drive. After these two things are set you can select apply and wait until the image is applied. The following is a screenshot of "  & @CRLF & _
                                               "GImageX with the correct directories." & @CRLF & _
                                               " " & @CRLF & _
                                               " ", 10, 45, 683)
            $image3 = GUICtrlCreatePic("gimagex.jpg", 25, 200, 538, 169)
        $bootRecTab = GUICtrlCreateTabItem("BootRec")
            $title7 = GuiCtrlCreateLabel("BootRec Process", 10, 30)
            $description7 = GuiCtrlCreateLabel("Uses BootRec /rebuildbcd command line utility to rebuild the boot manager for Windows 7." & @CRLF & _
                                               " "  & @CRLF & _
                                               "    After clicking the button the command BootRec /rebuildbcd is launched in the command prompt. Verify that it recognized the proper" & @CRLF & _
                                               " Windows partition and type Y or Yes to confirm. It will then compete the process and you can exit."  & @CRLF & _
                                               " "  & @CRLF & _
                                               " ", 10, 45, 683)
        $driversTab = GUICtrlCreateTabItem("Drivers")
            $title8 = GUICtrlCreateLabel("Process for Copying Drivers", 10, 30)
            $description8 = GuiCtrlCreateLabel("Uses AutoIT built in Copy Function, with custom DLL. "  & @CRLF & _
                                               " " & @CRLF & _
                                               "    After clicking the button a progress window will open and show you the percentage of drivers copied. If it failes use XCOPY commands below." & @CRLF & _
                                               " " & @CRLF & _
                                               " ", 10, 45, 683)

            $command4 = GUICtrlCreateInput('xcopy "y:\' & $platform & '\' & $model & ' ' & $modelnum & '\x86\Win7\DriverPack" C:\drivers\computer\ /S /Y', 10, 160, 683, 20)
            $command4 = GUICtrlCreateInput('xcopy "y:\DriverPacks\x86" C:\drivers\general\ /S /Y', 10, 190, 683, 20)
;;  Set Instruction Page state to shown
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWindow")
    GUISwitch($instructionForm)
    GUISetState(@SW_SHOW,$instructionForm)
EndFunc
#endregion Instruction Page
#Region About
;About form
Func About()
    Opt("GUIOnEventMode", 1)
    Global $aboutForm = GUICreate("FWM Sysprep - About", 400, 300)
    $aboutpic = GUICtrlCreatePic(".\Pictures\about.jpg", 0, 0, 400, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWindow")
    GUISwitch($aboutForm)
    GUISetState(@SW_SHOW, $aboutForm)
EndFunc
#EndRegion About
#Region Exits
Func CloseWindow()
    If @GUI_WINHANDLE = $Main Then
        $logFile = FileOpen($logFN,1)
        FileWriteLine($logFile, "Script end: " & _NowTime())
        FileClose($logFile)
        DirCreate($drive & '\LogFiles\Sysprep\' & @Mon & '_' & @MDAY & '_' & @YEAR)
        FileCopy($logFN, $drive & '\LogFiles\Sysprep\' & @Mon & '_' & @MDAY & '_' & @YEAR & '\')
        MsgBox(0, "Log File Moved", "Logfile was moved from WinPE. Locate it at " & $drive & "\LogFiles\Sysprep\" & @Mon & "_" & @MDAY & "_" & @YEAR & "\")
        Exit
    ElseIf @GUI_WINHANDLE = $instructionForm Then
        GUISetState(@SW_HIDE, $instructionForm)
        GUISwitch($Main)
    ElseIf @GUI_WinHandle = $aboutForm Then
        GUISetState(@SW_HIDE, $aboutForm)
        GUISwitch($Main)
    Elseif @GUI_WINHANDLE = $filenamePrompt Then
        GUISetState(@SW_HIDE, $filenamePrompt)
        GUISwitch($Main)
    EndIf
EndFunc
#endregion

Also required is an ErrorInterpreter (I presume that this is something that original script writer also created):

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Error Interpreter for SySprep;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Interpreter($function, $error, $extra = 'null')
    Global $Logfile = FileOpen($logFN, 1)
    If $function = 'Ping' Then
        $errorcode  = _Ping_Errors($error)
    ElseIf $function = 'Map' Then
        $errorcode  = _MapDrive_Errors($error, $extra)
    Elseif $function = 'USB' Then
        $errorcode = _USB_Errors($error, $extra)
    Elseif $function = 'Data' Then
        $errorcode = _Data_Errors($error)
    ElseIf $function = 'Backup' Then
        $errorcode = _Backup_Errors($error)
    ElseIf $function = 'USMT' Then
        $errorcode = _USMT_Errors($error)
    Elseif $function = 'DiskPart' Then
        $errorcode = _DiskPart_Errors($error)
    Elseif $function = 'Image' Then
        $errorcode = _Image_Errors($error)
    Elseif $function = 'Boot' Then
        $errorcode = _BootRec_Errors($error)
    Elseif $function = 'Driver' Then
        $errorcode = _Driver_Errors($error)
    Elseif $function = 'Hotkey' Then
        $errorcode = _Hotkey_Errors($error)
    EndIf
    FileClose($Logfile)
    Return $errorcode
EndFunc
#Region Ping Errors
;When the function fails (returns 0) @error contains extended information:
;; 1 = Host is offline
;; 2 = Host is unreachable
;; 3 = Bad destination
;; 4 = Other errors
Func _Ping_Errors($error)
    If $error = 0 Then
        FileWriteLine($Logfile, "Network Connection Established.")
    Elseif $error = 1 Then
        FileWriteLine($LogFile, "Network connection failed. Host appears to be offline.")
    Elseif $error = 2 Then
        FileWriteLine($Logfile, "Network connection failed. Host is unreachable.")
    ElseIf $error = 3 Then
        FileWriteline($Logfile, "Network connection filed. Destination does not exist.")
    Elseif $error = 4 Then
        FileWriteLine($Logfile, "Network connection failed. Unknown error occured. Contact your system administrator for help.")
    EndIf
    Return $error
EndFunc
#endregion
#Region Map Drive Errors
;When the function fails (returns 0) @error contains extended information:
;; 1 = Undefined / Other error. @extended set with Windows API return
;; 2 = Access to the remote share was denied
;; 3 = The device is already assigned
;; 4 = Invalid device name
;; 5 = Invalid remote share
;; 6 = Invalid password
Func _MapDrive_Errors($error, $drive = "null")
    Select
    Case $error = 0 
        FileWriteLine($Logfile, $drive & " drive successfully mapped.")
    Case $error = 1 
        FileWriteLine($Logfile, $drive & " drive did not map correctly. Try mapping drive using 'NET USE' command to see error.")
    Case $error = 2 
        FileWriteLine($Logfile, $drive & " drive did not map correctly. Access to the remote shared was denied.")
    Case $error = 3
        FileWriteLine($Logfile, $drive & " drive did not map correctly. The device is already assigned.")
    Case $error = 4 
        FileWriteLine($Logfile, $drive & " drive did not map correctly. Invalid device name.")
    case $error = 5 
        FileWriteLine($Logfile, $drive & " drive did not map correctly. Invalid remote share.")
    Case $error = 6
        FileWriteLine($Logfile, $drive & " drive did not map correctly. Invalid password.")
    EndSelect
    Return $error
EndFunc
#endregion
#Region USB Errors
Func _USB_Errors($error, $drive = "null")
    Select
    Case $error = 0 
        FileWriteLine($Logfile, "Found drive " & $drive & ".")
    Case $error = 1 
        FileWriteLine($Logfile, "No removeable drive found. Setting variables to defaults.")
    EndSelect
    Return $error
EndFunc
#endregion
#Region Data Errors
Func _Data_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "System make, model, computername, and username loaded successfully with specific data." & @CRLF & _
                                "Make: " & $model & @CRLF & _ 
                                "Model: " & $modelnum & @CRLF & _ 
                                "Computername: " & $compname & @CRLF & _ 
                                "Username: " & $username)
    Case $error = 1
        FileWriteLine($Logfile, "System make, model, computername, and username loaded successfully with default NEW BUILD data.")
    Case $error = 2
        FileWriteLine($Logfile, "System make, model, computername, and username loaded successfully with default data.")
    Case $error = 9
        FileWriteLine($Logfile, "Data.txt found on removeable media.")
    Case $error = 99
        FileWriteLine($Logfile, "Data.txt not found on removeable media.")
    EndSelect
EndFunc
#endregion
#Region HotKey
Func _Hotkey_Errors($error)
    Select
    Case $error = 1
        FileWriteLine($Logfile, "Manual Override key used. I hope you know what you are doing.")
    EndSelect
EndFunc
#endregion
#Region Backup Errors
Func _Backup_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "Backup operation ran. View backup log in " & @SystemDir & "\Logfiles\backup.log")
    Case $error = 1
        FileWriteLine($Logfile, "No partition selected to backup. Exiting. Please try again and enter in a partition number.")
    Case $error = 2
        FileWriteLine($Logfile, "Chosen partition does not match the results found by the system.")
    Case $error = 3
        FileWriteLine($Logfile, "Sysprep did not find C: drive on computer. Run command manually to backup partition.")
    EndSelect
EndFunc
#endregion
#Region USMT Errors
Func _USMT_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "USMT operation ran. View migration log in " & @SystemDir & "\Logfiles\scanstate.log. Files.txt will also show you which files it moved.")
    Case Else
        FileWriteLine($Logfile, "USMT operation ran. Unknown Error Occured")
    EndSelect
EndFunc
#endregion
#Region DiskPart Errors
Func _DiskPart_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "Disk Part operation Ran. Drive is now blank and has been formatted.")
    Case $error = 1
        FileWriteLine($Logfile, "Automation Error: Could not read command line output, operation aborted.Run Disk Part Manually.")
    Case $error = 2
        FileWriteLine($Logfile, "Automation Error: Could not find C: drive, operation aborted. Run Disk Part Manually.")
    Case $error = 3
        FileWriteLine($Logfile, "Automation Error: Unknown configuration occurred, drive not formatted. Run Disk Part Manually.")
    EndSelect
EndFunc
#endregion
#Region ImageX Errors
Func _Image_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "Drive Imaged successfully.")
    EndSelect
EndFunc
#endregion
#Region BootRec Errors
Func _BootRec_Errors($error)
EndFunc
#endregion
#Region Driver Errors
Func _Driver_Errors($error)
    Select
    Case $error = 0
        FileWriteLine($Logfile, "Drivers copied successfully.")
    Case $error = 1
        FileWriteLine($Logfile, "Copy.DLL did not load or was not found.")
    Case $error = 2
        FileWriteLine($Logfile, "Drivers copied successfully.")
    EndSelect
EndFunc
#endregion

The function that is giving me trouble does eventually use the Copy UDF written by Yashied.  The version of the script that works uses 1.3 of the Copy UDF.

One thing I should throw out there is I do not have access to the source of the older, working script.  We use TFS in our environment, but apparently he decided to overwrite the older, known good version with the broken, new version, so that is all I have a record of.  I'm just glad I have that at least....

Thanks

Link to comment
Share on other sites

  • Solution

The problem lies in the fact that the script is using OnEvent mode, and you can't use GUIGetMsg with OnEvent mode in the same script without switching it off first. Whoever wrote this script actually uses this line "Opt("GUIOnEventMode", 1)" 4 times when you only need it once.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ah ha! You, sir, are a genius.  I never would have caught that.

At the begining of my first code snippet, I added a line that read: Opt("GUIOnEventMode", 0)

For now, where that particular function exits, I added: Opt("GUIOnEventMode", 1) this seemed to keep everything working.  When I have more time I will dive into all of the extra instances of that command.

Thanks for you help!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...