Sign in to follow this  
Followers 0
AlchemistZim

Function not exiting properly

9 posts in this topic

Part of my script lets a user map to a network share. It working properly except when a mistake is made. If it doesn't connect, it asks if you want to try again which reruns the function. Problem is when they do finally make a connection it asks if they want to select a folder. regardless if they select a folder or not, they get prompted to select a folder with the previous variables where mistakes were made. How do I get the function to return to the 1st gui without it looping back on itself.

#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

GUICreate("Test", 100, 100)
$Run = GUICtrlCreateButton("GO", 10, 10, 80, 80)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Run
                MapShare()
        EndSwitch
    WEnd

MapShare()

Global $gShare
Func MapShare()
    $drive = ""
    $user = ""
    $pass = ""

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return
        EndSwitch
    WEnd
    
    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    If $drive = "" Then
        MsgBox(0,"Error","'Connect to' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $user = "" Then
        MsgBox(0,"Error","'Username' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $pass = "" Then
        MsgBox(0,"Error","'Password' field required")
        GUIDelete()
        MapShare()
    EndIf
    
    GUIDelete()
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then 
        $Retry = MsgBox(4,"Error","Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then 
            MapShare()
        Else
            Return
        EndIf
    EndIf

    $Open = MsgBox(4,"","Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
        If $Open = 6 Then 
            $Select = FileSelectFolder("Choose a Folder", $drive, 1)
            If $Select = "" Then Return
            Msgbox(0,"",$Select)
        Else
            Return
        EndIf
EndFunc

Share this post


Link to post
Share on other sites



It's brute force, but you can flush the variables after failure and make them fill it out again. Set them to Default, Null, zero, blank, something unique.... and then test for it.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Part of my script lets a user map to a network share. It working properly except when a mistake is made. If it doesn't connect, it asks if you want to try again which reruns the function. Problem is when they do finally make a connection it asks if they want to select a folder. regardless if they select a folder or not, they get prompted to select a folder with the previous variables where mistakes were made. How do I get the function to return to the 1st gui without it looping back on itself.

#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

GUICreate("Test", 100, 100)
$Run = GUICtrlCreateButton("GO", 10, 10, 80, 80)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Run
                MapShare()
        EndSwitch
    WEnd

MapShare()

Global $gShare
Func MapShare()
    $drive = ""
    $user = ""
    $pass = ""

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return
        EndSwitch
    WEnd
    
    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    If $drive = "" Then
        MsgBox(0,"Error","'Connect to' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $user = "" Then
        MsgBox(0,"Error","'Username' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $pass = "" Then
        MsgBox(0,"Error","'Password' field required")
        GUIDelete()
        MapShare()
    EndIf
    
    GUIDelete()
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then 
        $Retry = MsgBox(4,"Error","Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then 
            MapShare()
        Else
            Return
        EndIf
    EndIf

    $Open = MsgBox(4,"","Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
        If $Open = 6 Then 
            $Select = FileSelectFolder("Choose a Folder", $drive, 1)
            If $Select = "" Then Return
            Msgbox(0,"",$Select)
        Else
            Return
        EndIf
EndFunc

I recommend that you make a change to the way that you have written it because you are using the mapshare function recursively but it doesn't look like that the function was written to do that. It's not obvious to me how you will control the level of recursion and I would expect lots of problems. I think it is better toi return from the script completly then start it again. Otherwise, you start the script again then when it returns, for whatever reason, it carries on where it left off with, as you said, the same values for the variables. If you return with a different number depending on the reason then you can react in a controlled way and, if sensible, run the function again, and you can be sure the variables are all refreshed.

Eg

#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

GUICreate("Test", 100, 100)
$Run = GUICtrlCreateButton("GO", 10, 10, 80, 80)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Run
            While 1
                $mapError = MapShare()
                Switch $mapError
                    Case 3
                        ;do something
                    Case 1
                        ;something else maybe
                EndSwitch
                If $mapError = -1 Then ExitLoop
            WEnd
    EndSwitch
WEnd

;MapShare()

;Global $gShare
Func MapShare()
    $drive = ""
    $user = ""
    $pass = ""

    #region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return 1
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return 1
        EndSwitch
    WEnd

    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    If $drive = "" Then
        MsgBox(0, "Error", "'Connect to' field required")
        GUIDelete()
        Return 2;MapShare()
    EndIf
    If $user = "" Then
        MsgBox(0, "Error", "'Username' field required")
        GUIDelete()
        Return 3; MapShare()
    EndIf
    If $pass = "" Then
        MsgBox(0, "Error", "'Password' field required")
        GUIDelete()
        Return 4;MapShare()
    EndIf

    GUIDelete()
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then
        $Retry = MsgBox(4, "Error", "Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then
            Return 3;MapShare()
        Else
            Return -1
        EndIf
    EndIf

    $Open = MsgBox(4, "", "Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
    If $Open = 6 Then
        $Select = FileSelectFolder("Choose a Folder", $drive, 1)
        If $Select = "" Then Return
        MsgBox(0, "", $Select)
    Else
        Return -1
    EndIf
EndFunc   ;==>MapShare

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I don't want to to be recursive. All I want is for the function to map a network share, if they screw up they can try again. if they get it right, they can either select a folder, or return to the MAIN GUI. I was trying to prevent having to click on the button again to bring up the gui to get to the mapshare function, but if thats the case so be it. just to show you what i was trying to do here is the entire script.

;Set AutoIt Options
Opt("TrayIconHide",1)
Opt("WinTitleMatchMode", 2)

;Set AutoItWrapper Options
#AutoIt3Wrapper_Res_requestedExecutionLevel = requireAdministrator
#AutoIt3Wrapper_Icon = "\\namdco046\Shares\Columbia\Common To All - Temporary File Transfer Area\Mike Brown\z-Custom Tools\1-source files\greene's+g+icon.ico"
#AutoIt3Wrapper_OutFile = "\\2007-0503\c$\Documents and Settings\All Users\Desktop\Refresh Tool v4.1.exe"
;#AutoIt3Wrapper_OutFile = "\\namdco046\Shares\Columbia\Refresh Tool v4.1.exe"

;Include extra scripts
#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

;Set Global Variables
Global $Setup, $Busy, $Stage, $Busy, $gShare, $Share, $optUser, $optCom, $Find, $TotSize, $FreeSpace, $SelSize, $Progress, $Kill, $BartPE
Global $bRadio1, $bRadio2, $bRadio3, $rRadio1, $rRadio2, $rRadio3
Global $RefreshDir = @ScriptDir & "\z-refresh4\"

;Get Total File Size 
$TotSize = Round(DirGetSize(@UserProfileDir)/1024/1024/1024, 2) + Round((DriveSpaceTotal("C:\") - DriveSpaceFree("C:\"))/1024, 2)

;BartPE Check
$var = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\PE Builder", "Product")
If Not $var = "" Then
    $BartPE = 1
EndIf

AdminChk()

;Main GUI Window
Func MainGUI()
    #Region ### START Koda GUI section ### Form=
    $Setup = GUICreate("Refresh Tool v4.1", 501, 501)
    $gUser = GUICtrlCreateLabel("Username: " & @UserName, 5, 10, 200, 17)
    $gCom = GUICtrlCreateLabel("Computer: " & @ComputerName, 8, 30, 200, 17)
    $Browse = GUICtrlCreateButton("Browse", 10, 55, 75, 37, $BS_DEFPUSHBUTTON)
    $MapShr = GUICtrlCreateButton(" Map" & @CRLF & "Drive", 10, 95, 75, 37, $BS_MULTILINE)
    $gShare = GUICtrlCreateInput("", 90, 75, 320, 20)
    $ChkSze = GUICtrlCreateButton("Check" & @CRLF & " Size", 415, 67, 75, 37, $BS_MULTILINE)
    $optUser = GUICtrlCreateCheckbox("Add %username% to path", 90, 95, 150, 25)
    $optCom = GUICtrlCreateCheckbox("Add %computer% to path", 250, 95, 150, 25)
    $NeedSpace = GUICtrlCreateLabel("Needed Space: " & $TotSize & " GB", 236, 10, 150, 17)
        GUICtrlSetTip(-1, "This is approximately the amount of space needed to" & @CRLF & "successfully do a data transfer and Ghost image" & @CRLF & "!!!More Space may probably be needed!!!")
    $FreeSpace = GUICtrlCreateLabel("Free Space: ", 253, 30, 150, 17)

    If $BartPE = 1 Then GUICtrlSetState($MapShr, $GUI_DISABLE)
        
    $Tab1 = GUICtrlCreateTab(0, 150, 500, 350)
        $TabSheet1 = GUICtrlCreateTabItem("Backup")
            $bTabTip = GUICtrlCreateLabel("Old Computer (Source PC)" & @CRLF & "- This is the computer I want to transfer files and settings from.", 9, 175, 541, 38)
            $bRadio1 = GUICtrlCreateRadio("WinXP to WinXP", 35, 241, 200, 20)
            GUICtrlSetState(-1, $GUI_CHECKED)
            $bRadio2 = GUICtrlCreateRadio("WinXP to Win7", 35, 281, 200, 20)
            $bRadio3 = GUICtrlCreateRadio("Win7 to Win7", 35, 321, 200, 20)
            $bGhost = GUICtrlCreateButton("   Backup" & @CRLF & "Ghost Only", 16, 432, 100, 50, $BS_MULTILINE)
            GUICtrlSetTip(-1, "This is approximately the amount of space needed to" & @CRLF & "successfully do a data transfer and Ghost image" & @CRLF & "!!!More Space may probably be needed!!!")
            $bDaGho = GUICtrlCreateButton("    Backup" & @CRLF & "USMT-Ghost", 192, 432, 100, 50, $BS_MULTILINE)
            $bData = GUICtrlCreateButton("Backup" & @CRLF & " USMT", 377, 432, 100, 50, $BS_MULTILINE)
            GUICtrlSetState($bGhost, $GUI_DISABLE)
            GUICtrlSetState($bDaGho, $GUI_DISABLE)
            GUICtrlSetState($bData, $GUI_DISABLE)
            
        $TabSheet2 = GUICtrlCreateTabItem("Restore")
            $rTabTip = GUICtrlCreateLabel("New Computer (Destination PC)" & @CRLF & "- This is the computer I want to transfer files and settings to.", 9, 175, 541, 38)
            $rRadio1 = GUICtrlCreateRadio("WinXP to WinXP", 35, 241, 200, 20)
            GUICtrlSetState(-1, $GUI_CHECKED)
            $rRadio2 = GUICtrlCreateRadio("WinXP to Win7", 35, 281, 200, 20)
            $rRadio3 = GUICtrlCreateRadio("Win7 to Win7", 35, 321, 200, 20)
            $rGhost = GUICtrlCreateButton("   Restore" & @CRLF & "Ghost Only", 16, 432, 100, 50, $BS_MULTILINE)
            $rData = GUICtrlCreateButton("Restore" & @CRLF & " USMT", 377, 432, 100, 50, $BS_MULTILINE)
            GUICtrlSetState($rGhost, $GUI_DISABLE)
            GUICtrlSetState($rData, $GUI_DISABLE)
    GUICtrlCreateTabItem("")

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Cleanup()
            Case $Browse
                SelFold()
            Case $ChkSze
                CheckSize()
            Case $MapShr
                MapShare()
            Case $bGhost
                Setup()
                bGhost()
                Cancel()
            Case $bDaGho
                Setup()
                Backup()
                bGhost()
                Cancel()
            Case $bData
                Setup()
                Backup()
                Cancel()
            Case $rGhost
                Setup()
                rGhost()
                Cancel()
            Case $rData
                Setup()
                Restore()
                Cancel()
        EndSwitch
    
        If FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bGhost), $GUI_ENABLE) Then GUICtrlSetState($bGhost, $GUI_ENABLE)
        If FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bDaGho), $GUI_ENABLE) And Not $BartPE = 1 Then GUICtrlSetState($bDaGho, $GUI_ENABLE)
        If FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bData), $GUI_ENABLE) And Not $BartPE = 1 Then GUICtrlSetState($bData, $GUI_ENABLE)
        If FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($rGhost), $GUI_ENABLE) And $BartPE = 1 Then GUICtrlSetState($rGhost, $GUI_ENABLE)
        If FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($rData), $GUI_ENABLE) And Not $BartPE = 1 Then GUICtrlSetState($rData, $GUI_ENABLE)
            
        
        If Not FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bGhost), $GUI_DISABLE) Then GUICtrlSetState($bGhost, $GUI_DISABLE)
        If Not FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bDaGho), $GUI_DISABLE) And Not $BartPE = 1 Then GUICtrlSetState($bDaGho, $GUI_DISABLE)
        If Not FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($bData), $GUI_DISABLE) And Not $BartPE = 1 Then GUICtrlSetState($bData, $GUI_DISABLE)
        If Not FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($rGhost), $GUI_DISABLE) And $BartPE = 1 Then GUICtrlSetState($rGhost, $GUI_DISABLE)
        If Not FileExists(GUICtrlRead($gShare)) And Not BitAND(GUICtrlGetState($rData), $GUI_DISABLE) And Not $BartPE = 1 Then GUICtrlSetState($rData, $GUI_DISABLE)

    WEnd
EndFunc

;Setup 'data store' and files for user
Func Setup()
    $Kill = 0
        
    $Share = GUICtrlRead($gShare)
    If $Share = "" Then 
        MsgBox(0, "No Folder Selected", "You have not chosen a folder to save data to" & @CRLF & "Please choose a valid folder to save data to")
        $Kill = 1
        Return
    ElseIf Not FileExists($Share) Then
        MsgBox(0, "No Folder Exists", "The folder you have chosen doesn't exist" & @CRLF & "Please choose a valid folder to save data to")
        $Kill = 1
        Return
    ElseIf (FileExists($Share)) And Not (StringRight($Share,1) = "\") Then
        $Share = GUICtrlRead($gShare) & "\"
    EndIf
    
    If (FileExists($Share)) And (GUICtrlRead($optUser) = 1) And (GUICtrlRead($optCom) = 4) Then
        $Share = $Share & @Username & "\"
    ElseIf (FileExists($Share)) And (GUICtrlRead($optUser) = 4) And (GUICtrlRead($optCom) = 1) Then
        $Share = $Share & @ComputerName & "\"
    ElseIf (FileExists($Share)) And (GUICtrlRead($optUser) = 1) And (GUICtrlRead($optCom) = 1) Then
        $Share = $Share & @Username & "-" & @ComputerName & "\"
    EndIf

    If Not FileExists($Share) Then DirCreate($Share)
        
    BusyBox()
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
        
    ;Install Files
    If Not (FileExists($RefreshDir)) Or Not (DirGetSize($RefreshDir) = 82564702) Then
        DirRemove($RefreshDir, 1)
        DirCreate($RefreshDir)
        GUICtrlSetData($Stage, "Copying Files")
        GUICtrlSetData($Progress, 25)
        FileInstall("\\namdco046\Shares\Columbia\Common To All - Temporary File Transfer Area\Mike Brown\z-Custom Tools\1-source files\7z.exe", $RefreshDir)
        FileInstall("\\namdco046\Shares\Columbia\Common To All - Temporary File Transfer Area\Mike Brown\z-Custom Tools\1-source files\refreshv4.0.zip", $RefreshDir)
        
        GUICtrlSetData($Stage, "Expanding Files")
        GUICtrlSetData($Progress, 40)
        $7zip = Run('"' & $RefreshDir & "7z.exe" & '"' & " x -o"  & '"' & $RefreshDir  & '"' & " -y "  & '"' & $RefreshDir & "refreshv4.0.zip" & '"', "", @SW_HIDE)
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($7zip)
    EndIf

    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
EndFunc

;Backup routine
Func Backup()
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    ;Copy saplogon.ini to backup folder
    FileCopy("c:\WINDOWS\saplogon.ini", $Share, 1)
    
    ;Copy LabelPrinter.ini to backup folder
    If FileExists("c:\windows\LabelPrinter.ini") Then FileCopy("c:\windows\LabelPrinter.ini", $Share, 1)
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    ;Run CCleaner & close
    GUICtrlSetData($Stage, "Running CC Cleaner")
    GUICtrlSetData($Progress, 55)
    $Cleaner = Run('"' & $RefreshDir & "CCleaner\CCleaner.exe" & '"' & " /Auto")
    WinActivate("PC Refresh-Running")
    ProcessWaitClose($Cleaner)

    GUICtrlSetData($Stage, "Running USMT")
    GUICtrlSetData($Progress, 70)
    ;Backup - XP-XP
    If GUICtrlRead($bRadio1) = 1 Then
        ;Windows Version Check
        If @OSVersion = "WIN_7" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows 7" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Cancel()
            Return
        EndIf
        
        ;Previous Data Check
        If Not FileExists($Share & "1 XP-XP") Then DirCreate($Share & "1 XP-XP")
        If Not DirGetSize($Share & "1 XP-XP") = 0 Then
            $fold = MsgBox(4, "Data Exists", "USMT Data already exists" & @CRLF & "Do You want to overwrite data?")
            If $fold = 7 Then
                Cancel()
                Return
            Else
                DirRemove($Share & "1 XP-XP", 1)
                DirCreate($Share & "1 XP-XP")
            EndIf
        EndIf

        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf
    
        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT301-x86\ScanState.exe" & '"' & " " & '"' & $share & "1 XP-XP" & '"' & " /ue:*\* /ui:gracead\" & @UserName & " /config:config.xml /i:miguser.xml /i:migapp.xml /i:migsys.xml /i:custom.xml /i:map-print.xml /targetxp /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-XP-XP-scan.log" & '"', $RefreshDir & "USMT301-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
        
    ;Backup - XP-7
    ElseIf GUICtrlRead($bRadio2) = 1 Then
        ;Windows Version Check
        If @OSVersion = "WIN_7" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows 7" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Cancel()
            Return
        EndIf
        
        ;Previous Data Check
        If Not FileExists($Share & "2 XP-7") Then DirCreate($Share & "2 XP-7")
        If Not DirGetSize($Share & "2 XP-7") = 0 Then
            $fold = MsgBox(4, "Data Exists", "USMT Data already exists" & @CRLF & "Do You want to overwrite data?")
            If $fold = 7 Then
                Cancel()
                Return
            Else
                DirRemove($Share & "2 XP-7", 1)
                DirCreate($Share & "2 XP-7")
            EndIf
        EndIf
        
        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf

        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT401-x86\ScanState.exe" & '"' & " " & '"' & $share & "2 XP-7" & '"' & " /ue:*\* /ui:gracead\" & @UserName & " /config:config.xml /i:migdocs.xml /i:miguser.xml /i:migapp.xml /i:custom.xml /i:map-print.xml /c /localonly /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-XP-7-scan.log" & '"', $RefreshDir & "USMT401-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
                
    ;Backup - 7-7
    ElseIf GUICtrlRead($bRadio3) = 1 Then
        ;Windows Version Check
        If @OSVersion = "WIN_XP" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows XP" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Cancel()
            Return
        EndIf
        
        ;Previous Data Check
        If Not FileExists($Share & "3 7-7") Then DirCreate($Share & "3 7-7")
        If Not DirGetSize($Share & "3 7-7") = 0 Then
            $fold = MsgBox(4, "Data Exists", "Data already exists" & @CRLF & "Do You want to overwrite data?")
            If $fold = 7 Then
                Cancel()
                Return
            Else
                DirRemove($Share & "3 7-7", 1)
                DirCreate($Share & "3 7-7")
            EndIf
        EndIf
   
        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf
        
        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT401-x86\ScanState.exe" & '"' & " " & '"' & $share & "3 7-7" & '"' & " /ue:*\* /ui:gracead\" & @UserName & " /config:config.xml /i:migdocs.xml /i:miguser.xml /i:migapp.xml /i:custom.xml /i:map-print.xml /c /localonly /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-7-7-scan.log" & '"', $RefreshDir & "USMT401-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
        
    EndIf
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
        
    If $USMT = $PID Then
        MsgBox(0,"Backup", "USMT was successful",5)
    Else
        MsgBox(0,"Backup", "USMT was NOT successful" & @CRLF & "Please check logs for errors")
    EndIf
    
EndFunc

;Restore Routine
Func Restore()
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
        
    ;Restore saplogon.ini (backup existing saplogon.ini)
    If FileExists("c:\WINDOWS\saplogon.ini") Then
        If FileExists("c:\WINDOWS\saplogon.ini.org") Then
            FileMove("c:\WINDOWS\saplogon.ini.org", "c:\WINDOWS\saplogon.ini.bak", 1)
            FileMove("c:\WINDOWS\saplogon.ini", "c:\WINDOWS\saplogon.ini.org", 1)
        Else
            FileMove("c:\WINDOWS\saplogon.ini", "c:\WINDOWS\saplogon.ini.org", 1)
        EndIf
    EndIf
    FileCopy($Share & "saplogon.ini", "c:\WINDOWS\saplogon.ini")

    ;Restore LabelPrinter.ini to backup folder
    If FileExists($Share & "LabelPrinter.ini") Then FileCopy($Share & "LabelPrinter.ini", "c:\windows\LabelPrinter.ini", 1)
    
    GUICtrlSetData($Stage, "Running USMT")
    GUICtrlSetData($Progress, 70)
    ;Restore - XP-XP
    If GUICtrlRead($rRadio1) = 1 Then
    ;Windows Version Check
        If @OSVersion = "WIN_7" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows 7" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Cancel()
            Return
        EndIf
        
        If Not (FileExists($Share & "1 XP-XP")) Or (DirGetSize($Share & "1 XP-XP") = 0) Then
            MsgBox(0,"Missing Data", "There is no data in the selected folder" & @CRLF & "Please Try Again")
            Cancel()
            Return
        EndIf

        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf
        
        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT301-x86\LoadState.exe" & '"' & " " & '"' & $Share & "1 XP-XP" & '"' & " /config:config.xml /i:miguser.xml /i:migapp.xml /i:migsys.xml /i:custom.xml /i:map-print.xml /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-XP-XP-load.log" & '"', $RefreshDir & "USMT301-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
            
    ;Restore - XP-7
    ElseIf GUICtrlRead($rRadio2) = 1 Then
        ;Windows Version Check
        If @OSVersion = "WIN_XP" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows XP" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Cancel()
            Return
        EndIf
        
        If Not (FileExists($Share & "2 XP-7")) Or (DirGetSize($Share & "2 XP-7") = 0) Then
            MsgBox(0,"Missing Data", "There is no data in the selected folder" & @CRLF & "Please Try Again")
            Cancel()
            Return
        EndIf
        
        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf
    
        
        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT401-x86\LoadState.exe" & '"' & " " & '"' & $Share & "2 XP-7" & '"' & " /config:config.xml /i:miguser.xml /i:migdocs.xml /i:migapp.xml /i:custom.xml /i:map-print.xml /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-XP-7-load.log" & '"', $RefreshDir & "USMT401-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
            
    ;Restore - 7-7
    ElseIf GUICtrlRead($rRadio3) = 1 Then
        ;Windows Version Check
        If @OSVersion = "WIN_XP" Then
            MsgBox(48, "!!!WARNING!!!", "You are currently running Windows XP" & @CRLF& "Your current settings will NOT work" & @CRLF& "Please make another Selection")
            Return
        EndIf
        
        If Not (FileExists($Share & "3 7-7")) Or (DirGetSize($Share & "3 7-7") = 0) Then
            MsgBox(0,"Missing Data", "There is no data in the selected folder" & @CRLF & "Please Try Again")
            Cancel()
            Return
        EndIf
        
        If Not $Kill = 0 Then 
            Cancel()
            Return
        EndIf
    
        ;Run USMT
        $USMT = Run('"' & $RefreshDir & "USMT401-x86\LoadState.exe" & '"' & " " & '"' & $Share & "3 7-7" & '"' & " /config:config.xml /i:miguser.xml /i:migdocs.xml /i:migapp.xml /i:custom.xml /i:map-print.xml /v:13 /l:" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "-7-7-load.log" & '"', $RefreshDir & "USMT401-x86\")
        $PID = $USMT
        WinWait("State")
        WinActivate("PC Refresh-Running")
        ProcessWaitClose($USMT)
    EndIf
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
            
    If $PID = $USMT Then
        MsgBox(0,"Restore", "USMT was successful" & @CRLF & "Please logoff user")
    Else
        MsgBox(0,"Restore", "USMT was NOT successful" & @CRLF & "Please check logs for errors")
    EndIf
EndFunc 

;Create Ghost Image
Func bGhost()
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
        
    GUICtrlSetData($Stage, "Creating Ghost Image")
    GUICtrlSetData($Progress, 85)
    If Not FileExists($Share & "0 BACKUP") Then DirCreate($Share & "0 BACKUP")
    If Not DirGetSize($Share & "0 BACKUP") = 0 Then
        $fold = MsgBox(4, "Data Exists", "Data already exists" & @CRLF & "Do You want to overwrite data?")
        If $fold = 7 Then
            Cancel()
            Return
        Else
            DirRemove($Share & "0 BACKUP", 1)
            DirCreate($Share & "0 BACKUP")
        EndIf
    EndIf   
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    ;Run Ghost
    $Ghost = Run('"' & $RefreshDir & "Ghost\Ghost32.exe" & '"' & "-afile=" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "ghost-backup.log" & '"' & " -clone,src=1,dst=" & '"' & $Share & "0 BACKUP\" & @ComputerName & ".gho" & '"' & ",mode=create -sure -span -split=2048 -z1")
    $PID = $Ghost
    WinWait("Ghost32 11")
    WinActivate("PC Refresh-Running")
    ProcessWaitClose($Ghost)
        
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    If $PID = $Ghost Then
        MsgBox(0,"Ghost32", "Ghost image was created",10)
    Else
        MsgBox(0,"Ghost32", "Ghost image was NOT created" & @CRLF & "Please check logs for errors")
    EndIf
EndFunc

;Restore Ghost Image
Func rGhost()
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
        
    GUICtrlSetData($Stage, "Restoring Ghost Image")
    GUICtrlSetData($Progress, 85)
    ;Search for GHO location
    $gSearch = _RecFileListToArray($Share, "*gho", 1, 1, 0, 1)
    If @error = 1 Then 
        MsgBox(0,"Missing Data", "There is Ghost Image in the selected folder" & @CRLF & "Please Try Again")
        Cancel()
    Else
        $GhoImg = $Share & $gSearch[1]
    EndIf
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    ;Run Ghost
    $Ghost = Run('"' & $RefreshDir & "Ghost\Ghost32.exe" & '"' & "-afile=" & '"' & $share & @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC & "ghost-restore.log" & '"' & " -clone,mode=restore,src=" & '"' & $GhoImg & '"' & ",dst=1 -sure -rb")
    $PID = $Ghost
    WinWait("Ghost32 11.5.1")
    WinActivate("PC Refresh-Running")
    ProcessWaitClose($Ghost)
    
    If Not $Kill = 0 Then 
        Cancel()
        Return
    EndIf
    
    If $PID = $Ghost Then
        MsgBox(0,"Ghost32", "Ghost image was restored",10)
    Else
        MsgBox(0,"Ghost32", "Ghost image was NOT restored" & @CRLF & "Please check logs for errors")
    EndIf
EndFunc

;Check if current user is present in the admin group, exceptions for 'Administrator'(User), 'Windows 7'(OS), 'SYSTEM'(BartPE-User)
Func AdminChk()
    If @UserName = "Administrator" Or @OSVersion = "WIN_7" Or $BartPE = 1 Then 
        MainGUI()
    Else
        Search()
        If $Find = 0 Then
            $admin = MsgBox(4, "Admin Rights", "User " & @UserName & " does not have admin rights" & @CRLF & "Would you like to add him to the admin group?")
            If $admin = 6 Then 
                Admin()
            Else
                Cleanup()
            EndIf
        Else
            MainGUI()
        EndIf
    EndIf
EndFunc

;Set Admin Rights
Func Admin()
    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Set Admin Rights", 300, 300)
    $F1Label1 = GUICtrlCreateLabel("Admin Credentials", 123, 64, 55, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Username", 124, 116, 52, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Password", 125, 161, 50, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("", 83, 131, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 176, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $F1GO = GUICtrlCreateButton("GO", 88, 232, 121, 33, $BS_DEFPUSHBUTTON)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $F1GO
                ExitLoop
        EndSwitch
    WEnd
        
    $user = GUICtrlRead($F1Input1)
    $pass = GUICtrlRead($F1Input2)

    ;Error Checking (makes sure all fields have been filled out)
    If $user = "" Then
        MsgBox(0,"Error","Username field required")
        GUIDelete($Form1)
        Admin()
        Return
    EndIf
    If $pass = "" Then
        MsgBox(0,"Error","Password field required")
        GUIDelete($Form1)
        Admin()
        Return
    EndIf

    RunAsWait($user, "GRACEAD", $pass, 0, @COMSPEC & " /c Net Localgroup Administrators GRACEAD\" & @UserName & " /Add", @TempDir, @SW_HIDE)
    Search()
    If $Find = 0 Then
        $ErAdmin = MsgBox(4, "Error", "Unable to add user to the Admin group" & @CRLF & "User/pass is incorrect" & @CRLF & "Would you like to try again?")
        If $ErAdmin = 6 Then
            GUIDelete($Form1)
            Admin()
        Else
            GUIDelete($Form1)
            Cleanup()
        EndIf
    Else
        MsgBox(0,"Admin Rights", "User must logoff to get admin rights")
        Shutdown(20)
        Cleanup()
    EndIf
EndFunc

;Search Admin group for user name
Func Search()
    $List=Run(@COMSPEC & " /c " & "Net Localgroup Administrators" ,@TempDir,@SW_HIDE,$STDERR_MERGED)
    ProcessWaitClose($List)
    $Group=StdoutRead($List)
    $Find = StringInStr($Group, "GRACEAD\" & @UserName, 2)
EndFunc

;Select folder via GUI - 'Browse' button
Func SelFold()
    $Select = FileSelectFolder("Choose a Folder", "", 1)
    GUICtrlSetData($gShare, $Select)
    If GUICtrlRead($gShare) = "" Then Return
    CheckSize()
EndFunc

;Map Network Share
Func MapShare()
    $drive = ""
    $user = ""
    $pass = ""

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("\\", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return
        EndSwitch
    WEnd
    
    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    If $drive = "" Then
        MsgBox(0,"Error","'Connect to' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $user = "" Then
        MsgBox(0,"Error","'Username' field required")
        GUIDelete()
        MapShare()
    EndIf
    If $pass = "" Then
        MsgBox(0,"Error","'Password' field required")
        GUIDelete()
        MapShare()
    EndIf
    
    GUIDelete()
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then 
        $Retry = MsgBox(4,"Error","Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then 
            MapShare()
        Else
            Return
        EndIf
    EndIf

    $Open = MsgBox(4,"","Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
        If $Open = 6 Then 
            $Select = FileSelectFolder("Choose a Folder", $drive, 1)
            GUICtrlSetData($gShare, $Select)
        Else
            Return
        EndIf
        If GUICtrlRead($gShare) = "" Then Return
        CheckSize()
EndFunc

;Check folder size - 'Check Size' Button
Func CheckSize()
    If Not FileExists(GUICtrlRead($gShare)) Then
        MsgBox(0, "No Folder Exists", "The folder you have chosen doesn't exist" & @CRLF & "Please choose a valid folder to save data to")
        Return
    Else
        $SelSize = Round((DriveSpaceFree(GUICtrlRead($gShare))/1024), 2)
        GUICtrlSetData($FreeSpace, "Free Space: " & $SelSize & " GB")
        If ($TotSize + 5) >= $SelSize Then 
            GUICtrlSetColor($FreeSpace, 0xff0000)
            MsgBox(48, "!!!WARNING!!!", "The selected folder DOES NOT have enough space to complete" & @CRLF & "a full backup (Data & Ghost Image)" & @CRLF & @CRLF & "Please select another folder")
        EndIf
    EndIf
EndFunc

;Window displayed while application is doing something 
Func BusyBox()
    $deskw = @DesktopWidth - 200
    $deskh = @DesktopHeight - 170
    GUISetState(@SW_HIDE, $Setup)
    Opt("GUIOnEventMode", 1)
    $Busy = GUICreate("PC Refresh-Running", 152, 162, $deskw, 50, $WS_EX_TOPMOST)
    $Stage = GUICtrlCreateLabel("", 25, 10, 100, 40, $SS_CENTER)
    $Progress = GUICtrlCreateProgress(2, 40, 142, 20, $PBS_SMOOTH)
    $Marquee = GUICtrlCreateProgress(2, 70, 142, 20, $PBS_MARQUEE)
    $Cancel = GUICtrlCreateButton("CANCEL", 38, 93, 70, 30)
    GUICtrlSetOnEvent(-1, "PreExit")
    _SendMessage(GUICtrlGetHandle($Marquee), $PBM_SETMARQUEE, True, 100)
    Dim $Accel[1][2] = [["{ESC}", $Cancel]]
    GUISetAccelerators($Accel)
    GUISetState(@SW_SHOW)
EndFunc

;Close all running programs and return to GUI
Func Cancel()
    $Kill = 1
    GUICtrlSetData($Progress, 100)
    $bState = WinGetState("PC Refresh")
    ProcessClose("7z.exe")
    ProcessClose("CCleaner.exe")
    ProcessClose("ScanState.exe")
    ProcessClose("LoadState.exe")
    ProcessClose("ghost32.exe")
    GUISetAccelerators($Busy)
    Opt("GUIOnEventMode", 0)
    If BitAND($bState, 1) Then GUIDelete($Busy)
    GUISetState(@SW_SHOW, $Setup)
EndFunc
    
;If HotKey is pressed, ask before exiting app
Func PreExit()
    $Escape = MsgBox(4, "", "Are you sure you want to cancel?")
    If $Escape = 6 Then Cancel()
EndFunc

;Cleanup when app is closed normally (closes any running programs)
Func Cleanup()
    ProcessClose("7z.exe")
    ProcessClose("CCleaner.exe")
    ProcessClose("ScanState.exe")
    ProcessClose("LoadState.exe")
    ProcessClose("ghost32.exe")
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't want to to be recursive. All I want is for the function to map a network share, if they screw up they can try again. if they get it right, they can either select a folder, or return to the MAIN GUI. I was trying to prevent having to click on the button again....

The way I showed how to get round your problem meant they don't have to press a button again if you mean the "GO" button. I stopped it being recursive. I made it so if they screw up they can try again. I made it so the variables are refreshed everytime they try again.

I made it so that it behaved as the original as far as the operator is concerned but without the variables being retained and without the function calling itself and getting into a mess. From your reply it looks like either you misunderstood my suggestion or I've misunderstood your script.

I'm not likely to examine the whole script, I was just homing in on the problem you were trying to get round.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The way I showed how to get round your problem meant they don't have to press a button again if you mean the "GO" button. I stopped it being recursive. I made it so if they screw up they can try again. I made it so the variables are refreshed everytime they try again.

I made it so that it behaved as the original as far as the operator is concerned but without the variables being retained and without the function calling itself and getting into a mess. From your reply it looks like either you misunderstood my suggestion or I've misunderstood your script.

I'm not likely to examine the whole script, I was just homing in on the problem you were trying to get round.

thanks martin...i understand what your saying, but i guess i'm not understanding the loop that you added to the gui. if i'm screwing this up let me know.

While 1
                $mapError = MapShare()
                Switch $mapError
                    Case 3
                        ;do something
                    Case 1
                        ;something else maybe
                EndSwitch
                If $mapError = -1 Then ExitLoop
            WEnd

The Function is ran and the return variable is saved to $mapError, the different 'Return #' in the function will return that number. if the return is 3 then it will do something, if the return is 1 then it will do something else. so i could have the gui loop throw the error message instead of it being in the funtion itself. Is that about right???

Edited by AlchemistZim

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

OK i've made some changes based on what you said. can you tell me if this look right?. Also could I do a 'Case -1' instead of the 'If...-1'

#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

Global $gShare

GUICreate("Test", 100, 100)
$Run = GUICtrlCreateButton("GO", 10, 10, 80, 80)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Run
                While 1
                    $mCheck = MapShare()
                    Switch $mCheck
                        Case 1
                            MsgBox(0,"Error","'Connect to' field required")
                        Case 2
                            MsgBox(0,"Error","'Username' field required")
                        Case 3
                            MsgBox(0,"Error","'Password' field required")
                        Case 4
                    EndSwitch
                    If $mCheck = -1 Then ExitLoop
                WEnd
        EndSwitch
    WEnd


Func MapShare()
    
    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("\\", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return -1
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return -1
        EndSwitch
    WEnd
    
    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    GUIDelete()
    If $drive = "" Then Return 1
    If $user = "" Then Return 2
    If $pass = "" Then Return 3
    
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then 
        $Retry = MsgBox(4,"Error","Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then 
            Return 4
        Else
            Return -1
        EndIf
    EndIf

    $Open = MsgBox(4,"","Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
        If $Open = 6 Then 
            $Select = FileSelectFolder("Choose a Folder", $drive, 1)
            GUICtrlSetData($gShare, $Select)
        Else
            Return -1
        EndIf
        
        Return -1
EndFunc
Edited by AlchemistZim

Share this post


Link to post
Share on other sites

OK i've made some changes based on what you said. can you tell me if this look right?. Also could I do a 'Case -1' instead of the 'If...-1'

#include <Array.au3>
#include <Date.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <RecFileListToArray.au3>

Global $gShare

GUICreate("Test", 100, 100)
$Run = GUICtrlCreateButton("GO", 10, 10, 80, 80)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Run
                While 1
                    $mCheck = MapShare()
                    Switch $mCheck
                        Case 1
                            MsgBox(0,"Error","'Connect to' field required")
                        Case 2
                            MsgBox(0,"Error","'Username' field required")
                        Case 3
                            MsgBox(0,"Error","'Password' field required")
                        Case 4
                    EndSwitch
                    If $mCheck = -1 Then ExitLoop
                WEnd
        EndSwitch
    WEnd


Func MapShare()
    
    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Network Share", 300, 250)
    $F1Label1 = GUICtrlCreateLabel("Connect To" & @CRLF & "Network Share", 90, 15, 120, 34, $SS_CENTER)
    $F1Label2 = GUICtrlCreateLabel("Connect To", 100, 65, 100, 17, $SS_CENTER)
    $F1Label3 = GUICtrlCreateLabel("Username", 100, 105, 100, 17, $SS_CENTER)
    $F1Label4 = GUICtrlCreateLabel("Password", 100, 145, 100, 17, $SS_CENTER)
    $F1Input1 = GUICtrlCreateInput("\\", 83, 80, 137, 21)
    $F1Input2 = GUICtrlCreateInput("", 83, 120, 137, 21)
    $F1Input3 = GUICtrlCreateInput("", 83, 160, 137, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $GO = GUICtrlCreateButton("GO", 50, 200, 75, 33, $BS_DEFPUSHBUTTON)
    $NO = GUICtrlCreateButton("Cancel", 175, 200, 75, 33)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return -1
            Case $GO
                ExitLoop
            Case $NO
                GUIDelete()
                Return -1
        EndSwitch
    WEnd
    
    $drive = GUICtrlRead($F1Input1)
    $user = GUICtrlRead($F1Input2)
    $pass = GUICtrlRead($F1Input3)

    ;Error Checking (makes sure all fields have been filled out)
    GUIDelete()
    If $drive = "" Then Return 1
    If $user = "" Then Return 2
    If $pass = "" Then Return 3
    
    $map = DriveMapAdd("", $drive, 0, $user, $pass)
    If $map = 0 Then 
        $Retry = MsgBox(4,"Error","Unable to connect to share (" & $drive & ")" & @CRLF & "Would You like to Try Again")
        If $Retry = 6 Then 
            Return 4
        Else
            Return -1
        EndIf
    EndIf

    $Open = MsgBox(4,"","Connected to share (" & $drive & ")" & @CRLF & "Would You like select a folder")
        If $Open = 6 Then 
            $Select = FileSelectFolder("Choose a Folder", $drive, 1)
            GUICtrlSetData($gShare, $Select)
        Else
            Return -1
        EndIf
        
        Return -1
EndFunc

Looks OK to me and yes, Case -1 will be fine.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Looks OK to me and yes, Case -1 will be fine.

Thanks martin for all your help

Share this post


Link to post
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
Sign in to follow this  
Followers 0