Sign in to follow this  
Followers 0
polingkyle

GoTo Beginning-ish

6 posts in this topic

I wrote a GUI script that helps me inventory all of my servers by writing keys to the registry that I can query.  The GUI comes up and you fill out a form.  When you click OK, you are prompted for your credentials.  When you click OK again, it writes the keys and then shows a GUI with the keys that are written (to verify that the keys were written correctly).  I'm trying to add a "Go Back" button to the verification GUI that will loop back to the first GUI so changes can be made/correct.  When I hide the verification GUI to make changes, the buttons on the original GUI no longer work.  Any help on how to do accomplish this?  Here is what I have:

#RequireAdmin
#NoTrayIcon
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $USERNAME = EnvGet("USERNAME")

IF @CPUArch = "X86" Then
    $AppNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationName")
    $AppOwnerCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationOwner")
    $LocationCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Location")
    $PurposeCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Purpose")
    $DeptNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "DeptName")
    $Monitor1Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_1")
    $Monitor2Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_2")
    $Monitor3Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_3")
Else
    $AppNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationName")
    $AppOwnerCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationOwner")
    $LocationCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Location")
    $PurposeCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Purpose")
    $DeptNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "DeptName")
    $Monitor1Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_1")
    $Monitor2Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_2")
    $Monitor3Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_3")
EndIf

$Form1 = GUICreate("Server Registry Entries", 497, 371, 20, 20)
$ServerNameLabel = GUICtrlCreateLabel("Server Name:", 80, 56, 69, 17)
$ServerName = GUICtrlCreateInput(@ComputerName, 160, 56, 217, 21)
;AppName Dropdown Begin
$AppNameLabel = GUICtrlCreateLabel("Application Name", 64, 80, 87, 17)
IF $AppNameCurrent = "" Then
        $AppName = GUICtrlCreateCombo("Choose from dropdown menu", 160, 80, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $AppName = GUICtrlCreateCombo($AppNameCurrent, 160, 80, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "App1|App2|App3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;AppName Dropdown End
;AppOwner Dropdown Begin
$AppOwnerLabel = GUICtrlCreateLabel("Application Owner", 64, 104, 90, 17)
IF $AppOwnerCurrent = "" Then
        $AppOwner = GUICtrlCreateCombo("Choose from dropdown menu", 160, 104, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $AppOwner = GUICtrlCreateCombo($AppOwnerCurrent, 160, 104, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Owner1|Owner2|Owner3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;AppOwner Dropdown End
;DeptName Dropdown Begin
$DeptNameLabel = GUICtrlCreateLabel("Department Name", 64, 128, 90, 17)
IF $DeptNameCurrent = "" Then
        $DeptName = GUICtrlCreateCombo("Choose from dropdown menu", 160, 128, 217, 25, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $DeptName = GUICtrlCreateCombo($DeptNameCurrent, 160, 128, 217, 25, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Dept1|Dept2|Dept3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;DeptName Dropdown End
;Location Dropdown Begin
$LocationLabel = GUICtrlCreateLabel("Location of Server", 64, 152, 91, 17)
IF $LocationCurrent = "" Then
        $Location = GUICtrlCreateCombo("Choose from dropdown menu", 160, 152, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $Location = GUICtrlCreateCombo($LocationCurrent, 160, 152, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "City1|City2|City3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;Location Dropdown End
$PurposeLabel = GUICtrlCreateLabel("Purpose of Server", 64, 176, 89, 17)
$Purpose = GUICtrlCreateInput($PurposeCurrent, 160, 176, 217, 21)
;Monitor_1 Dropdown Begin
$Monitor1Label = GUICtrlCreateLabel("Monitor 1", 104, 200, 48, 17)
IF $Monitor1Current = "" Then
        $Monitor1 = GUICtrlCreateCombo("Choose from dropdown menu", 160, 200, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor1 = GUICtrlCreateCombo($Monitor1Current, 160, 200, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;Monitor_1 Dropdown EndFunc
;Monitor_2 Dropdown Begin
$Monitor2Label = GUICtrlCreateLabel("Monitor 2", 104, 224, 48, 17)
IF $Monitor2Current = "" Then
        $Monitor2 = GUICtrlCreateCombo("", 160, 224, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor2 = GUICtrlCreateCombo($Monitor2Current, 160, 224, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "")
GUISetState(@SW_SHOW)
;Monitor_2 Dropdown End
;Monitor_3 Dropdown Begin
$Monitor3Label = GUICtrlCreateLabel("Monitor 3", 104, 248, 48, 17)
IF $Monitor3Current = "" Then
        $Monitor3 = GUICtrlCreateCombo("", 160, 248, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor3 = GUICtrlCreateCombo($Monitor3Current, 160, 248, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "")
GUISetState(@SW_SHOW)
;Monitor_3 Dropdown End
$OK = GUICtrlCreateButton("OK", 168, 296, 75, 25, $BS_DEFPUSHBUTTON)
$Cancel = GUICtrlCreateButton("Cancel", 264, 296, 75, 25)
GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK

;BEGIN SCRIPT FOR CREDENTIAL INPUT
            HotKeySet("{Enter}", "_PressButton")
            $CredForm = GUICreate("Credentials", 368, 230, 80, 85)
            $DomainLabel = GUICtrlCreateLabel("Domain", 56, 64, 40, 17)
            $UsernameLabel = GUICtrlCreateLabel("Username", 48, 96, 52, 17)
            $PasswordLabel = GUICtrlCreateLabel("Password", 48, 128, 50, 17)
            $CredLabel = GUICtrlCreateLabel("Please enter your credentials:", 72, 24, 212, 24)
            $DomainInput = GUICtrlCreateCombo(@COMPUTERNAME, 120, 64, 161, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
            GUICtrlSetData(-1, @COMPUTERNAME & "|Domain1|Domain2")
            GUICtrlSetTip(-1, "Choose from dropdown")
            $UserInput = GUICtrlCreateInput("administrator", 120, 96, 161, 21)
            $PasswordInput = GUICtrlCreateInput("", 120, 128, 161, 21, $ES_PASSWORD)
            $CredOK = GUICtrlCreateButton("OK", 104, 176, 75, 25, $BS_DEFPUSHBUTTON)
            $CredCancel = GUICtrlCreateButton("Cancel", 192, 176, 75, 25)
            GUISetState(@SW_SHOW)
            GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico")

            While 1
                $nMsg1 = GUIGetMsg()
                Switch $nMsg1
                    Case $GUI_EVENT_CLOSE
                        Exit

                    Case $CredOK

;END SCRIPT FOR CREDENTIAL INPUT
                        $ServerNameRes = GUICtrlRead($ServerName)
                        $AppNameRes = GUICtrlRead($AppName)
                        $AppOwnerRes = GUICtrlRead($AppOwner)
                        $DeptNameRes = GUICtrlRead($DeptName)
                        $LocationRes = GUICtrlRead($Location)
                        $PurposeRes = GUICtrlRead($Purpose)
                        $Monitor1Res = GUICtrlRead($Monitor1)
                        $Monitor2Res = GUICtrlRead($Monitor2)
                        $Monitor3Res = GUICtrlRead($Monitor3)
                        $UserInputRes = GUICtrlRead($UserInput)
                        $DomainInputRes = GUICtrlRead($DomainInput)
                        $PasswordInputRes = GUICtrlRead($PasswordInput)

                        $RemRegSvc = 'SC \\' & $ServerNameRes & ' START "RemoteRegistry"'
                        $AppNameCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v ApplicationName /t REG_EXPAND_SZ /d "' & $AppNameRes & '"'
                        $AppOwnerCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v ApplicationOwner /t REG_Multi_SZ /d "' & $AppOwnerRes & '"'
                        $DeptNameCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v DeptName /t REG_EXPAND_SZ /d "' & $DeptNameRes & '"'
                        $LocationCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Location /t REG_EXPAND_SZ /d "' & $LocationRes & '"'
                        $Monitor1CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_1 /t REG_EXPAND_SZ /d "' & $Monitor1Res & '"'
                        $Monitor2CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_2 /t REG_EXPAND_SZ /d "' & $Monitor2Res & '"'
                        $Monitor3CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_3 /t REG_EXPAND_SZ /d "' & $Monitor3Res & '"'
                        $PurposeCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Purpose /t REG_EXPAND_SZ /d "' & $PurposeRes & '"'

                    ;Begin Write Registry Keys
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $RemRegSvc)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $AppNameCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $AppOwnerCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $DeptNameCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $LocationCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor1CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor2CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor3CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $PurposeCMD)
                    ;End Write Registry Keys

                    ;Begin Registry Key Verification
                        IF @CPUArch = "X86" Then
                            $AppNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationName")
                            $AppOwnerCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationOwner")
                            $LocationCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Location")
                            $PurposeCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Purpose")
                            $DeptNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "DeptName")
                            $Monitor1Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_1")
                            $Monitor2Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_2")
                            $Monitor3Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_3")
                        Else
                            $AppNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationName")
                            $AppOwnerCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationOwner")
                            $LocationCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Location")
                            $PurposeCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Purpose")
                            $DeptNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "DeptName")
                            $Monitor1Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_1")
                            $Monitor2Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_2")
                            $Monitor3Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_3")
                        EndIf


                        $FormComplet = GUICreate("CMG Server Registry Entries", 498, 372, 310, 124)
                        GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico", -1)
                        $Label1 = GUICtrlCreateLabel("Verify Registry Keys:", 160, 16, 181, 24)
                        GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                        $ServerNameCompLabel = GUICtrlCreateLabel("ServerName", 80, 59, 69, 17)
                        $AppNameCompLabel = GUICtrlCreateLabel("Application Name:", 59, 83, 90, 17)
                        $AppOwnerCompLabel = GUICtrlCreateLabel("Application Owner:", 58, 107, 93, 17)
                        $DeptNameCompLabel = GUICtrlCreateLabel("Department Name:", 57, 131, 93, 17)
                        $LocCompLabel = GUICtrlCreateLabel("Location of Server:", 56, 155, 94, 17)
                        $PurpCompLabel = GUICtrlCreateLabel("Purpose of Server:", 57, 179, 92, 17)
                        $Monitor1CompLabel = GUICtrlCreateLabel("Monitor 1:", 99, 203, 51, 17)
                        $Monitor2CompLabel = GUICtrlCreateLabel("Monitor 2:", 99, 227, 51, 17)
                        $Monitor3CompLabel = GUICtrlCreateLabel("Monitor 3:", 99, 251, 51, 17)
                        $ServerNameComp = GUICtrlCreateInput(@COMPUTERNAME, 160, 56, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $AppNameComp = GUICtrlCreateInput($AppNameCurrent, 160, 80, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $AppOwnerComp = GUICtrlCreateInput($AppOwnerCurrent, 160, 104, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $DeptNameComp = GUICtrlCreateInput($DeptNameCurrent, 160, 128, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $LocationComp = GUICtrlCreateInput($LocationCurrent, 160, 152, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $PurposeComp = GUICtrlCreateInput($PurposeCurrent, 160, 176, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor1Comp = GUICtrlCreateInput($Monitor1Current, 160, 200, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor2Comp = GUICtrlCreateInput($Monitor2Current, 160, 224, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor3Comp = GUICtrlCreateInput($Monitor3Current, 160, 248, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $BackButton = GUICtrlCreateButton("Go Back", 160, 304, 75, 25)
                        GUICtrlSetState(-1, $GUI_ENABLE)
                        $DoneButton = GUICtrlCreateButton("Exit", 260, 304, 75, 25, $BS_DEFPUSHBUTTON)
                        GUISetState(@SW_SHOW)

                        While 1
                            $nMsg = GUIGetMsg()
                            Switch $nMsg
                                Case $BackButton
                                    GUISetState(@SW_HIDE,$FormComplet)
                                    GUISetState(@SW_HIDE,$credform)
                                Case $GUI_EVENT_CLOSE
                                    Exit
                                Case $DoneButton
                                    Exit

                            EndSwitch
                        WEnd
                        ;End Registry Key Verification


                        Exit

                    Case $CredCancel
                        Exit

                EndSwitch
            WEnd



        Case $Cancel
            Exit
    EndSwitch
 WEnd

Share this post


Link to post
Share on other sites



Sorry man, I tried to de-spaghetti things but I think it would take too much time to complete.  Re-structuring things is what is needed.  What I suggest is just have 1 GUI, populate everything by your reg keys and use your defaults if the keys have no info, and let it be edited right in that one GUI.  Should be much simpler!

Also, you do not need to use GUISetState until the very end of creating all of the controls, it is not needed as often as you have it.  You also need to be careful with your GUISetIcon since it specifies a path that not all machines may have.

Ian


My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

polingkyle,

You buttons on the first gui do not seem to work because you are stuck in the second nested while...wend loop.  See the following to fix this...

#RequireAdmin
#NoTrayIcon
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $USERNAME = EnvGet("USERNAME")

IF @CPUArch = "X86" Then
    $AppNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationName")
    $AppOwnerCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationOwner")
    $LocationCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Location")
    $PurposeCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Purpose")
    $DeptNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "DeptName")
    $Monitor1Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_1")
    $Monitor2Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_2")
    $Monitor3Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_3")
Else
    $AppNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationName")
    $AppOwnerCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationOwner")
    $LocationCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Location")
    $PurposeCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Purpose")
    $DeptNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "DeptName")
    $Monitor1Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_1")
    $Monitor2Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_2")
    $Monitor3Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_3")
EndIf

$Form1 = GUICreate("Server Registry Entries", 497, 371, 20, 20)
$ServerNameLabel = GUICtrlCreateLabel("Server Name:", 80, 56, 69, 17)
$ServerName = GUICtrlCreateInput(@ComputerName, 160, 56, 217, 21)
;AppName Dropdown Begin
$AppNameLabel = GUICtrlCreateLabel("Application Name", 64, 80, 87, 17)
IF $AppNameCurrent = "" Then
        $AppName = GUICtrlCreateCombo("Choose from dropdown menu", 160, 80, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $AppName = GUICtrlCreateCombo($AppNameCurrent, 160, 80, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "App1|App2|App3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;AppName Dropdown End
;AppOwner Dropdown Begin
$AppOwnerLabel = GUICtrlCreateLabel("Application Owner", 64, 104, 90, 17)
IF $AppOwnerCurrent = "" Then
        $AppOwner = GUICtrlCreateCombo("Choose from dropdown menu", 160, 104, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $AppOwner = GUICtrlCreateCombo($AppOwnerCurrent, 160, 104, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Owner1|Owner2|Owner3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;AppOwner Dropdown End
;DeptName Dropdown Begin
$DeptNameLabel = GUICtrlCreateLabel("Department Name", 64, 128, 90, 17)
IF $DeptNameCurrent = "" Then
        $DeptName = GUICtrlCreateCombo("Choose from dropdown menu", 160, 128, 217, 25, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $DeptName = GUICtrlCreateCombo($DeptNameCurrent, 160, 128, 217, 25, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Dept1|Dept2|Dept3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;DeptName Dropdown End
;Location Dropdown Begin
$LocationLabel = GUICtrlCreateLabel("Location of Server", 64, 152, 91, 17)
IF $LocationCurrent = "" Then
        $Location = GUICtrlCreateCombo("Choose from dropdown menu", 160, 152, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
    Else
        $Location = GUICtrlCreateCombo($LocationCurrent, 160, 152, 217, 21, BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "City1|City2|City3")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;Location Dropdown End
$PurposeLabel = GUICtrlCreateLabel("Purpose of Server", 64, 176, 89, 17)
$Purpose = GUICtrlCreateInput($PurposeCurrent, 160, 176, 217, 21)
;Monitor_1 Dropdown Begin
$Monitor1Label = GUICtrlCreateLabel("Monitor 1", 104, 200, 48, 17)
IF $Monitor1Current = "" Then
        $Monitor1 = GUICtrlCreateCombo("Choose from dropdown menu", 160, 200, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor1 = GUICtrlCreateCombo($Monitor1Current, 160, 200, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "Choose from dropdown")
GUISetState(@SW_SHOW)
;Monitor_1 Dropdown EndFunc
;Monitor_2 Dropdown Begin
$Monitor2Label = GUICtrlCreateLabel("Monitor 2", 104, 224, 48, 17)
IF $Monitor2Current = "" Then
        $Monitor2 = GUICtrlCreateCombo("", 160, 224, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor2 = GUICtrlCreateCombo($Monitor2Current, 160, 224, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "")
GUISetState(@SW_SHOW)
;Monitor_2 Dropdown End
;Monitor_3 Dropdown Begin
$Monitor3Label = GUICtrlCreateLabel("Monitor 3", 104, 248, 48, 17)
IF $Monitor3Current = "" Then
        $Monitor3 = GUICtrlCreateCombo("", 160, 248, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
    Else
        $Monitor3 = GUICtrlCreateCombo($Monitor3Current, 160, 248, 217, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
EndIf
GUICtrlSetData(-1, "Email1@domain.com|Email2@domain.com|Email3@domain.com")
GUICtrlSetTip(-1, "")
GUISetState(@SW_SHOW)
;Monitor_3 Dropdown End
$OK = GUICtrlCreateButton("OK", 168, 296, 75, 25, $BS_DEFPUSHBUTTON)
$Cancel = GUICtrlCreateButton("Cancel", 264, 296, 75, 25)
GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK

;BEGIN SCRIPT FOR CREDENTIAL INPUT
            ;HotKeySet("{Enter}", "_PressButton")
            $CredForm = GUICreate("Credentials", 368, 230, 80, 85)
            $DomainLabel = GUICtrlCreateLabel("Domain", 56, 64, 40, 17)
            $UsernameLabel = GUICtrlCreateLabel("Username", 48, 96, 52, 17)
            $PasswordLabel = GUICtrlCreateLabel("Password", 48, 128, 50, 17)
            $CredLabel = GUICtrlCreateLabel("Please enter your credentials:", 72, 24, 212, 24)
            $DomainInput = GUICtrlCreateCombo(@COMPUTERNAME, 120, 64, 161, 21, BitOR($CBS_DROPDOWN,$GUI_SS_DEFAULT_COMBO))
            GUICtrlSetData(-1, @COMPUTERNAME & "|Domain1|Domain2")
            GUICtrlSetTip(-1, "Choose from dropdown")
            $UserInput = GUICtrlCreateInput("administrator", 120, 96, 161, 21)
            $PasswordInput = GUICtrlCreateInput("", 120, 128, 161, 21, $ES_PASSWORD)
            $CredOK = GUICtrlCreateButton("OK", 104, 176, 75, 25, $BS_DEFPUSHBUTTON)
            $CredCancel = GUICtrlCreateButton("Cancel", 192, 176, 75, 25)
            GUISetState(@SW_SHOW)
            GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico")

            While 1
                $nMsg1 = GUIGetMsg()
                Switch $nMsg1
                    Case $GUI_EVENT_CLOSE
                        Exit

                    Case $CredOK

;END SCRIPT FOR CREDENTIAL INPUT
                        $ServerNameRes = GUICtrlRead($ServerName)
                        $AppNameRes = GUICtrlRead($AppName)
                        $AppOwnerRes = GUICtrlRead($AppOwner)
                        $DeptNameRes = GUICtrlRead($DeptName)
                        $LocationRes = GUICtrlRead($Location)
                        $PurposeRes = GUICtrlRead($Purpose)
                        $Monitor1Res = GUICtrlRead($Monitor1)
                        $Monitor2Res = GUICtrlRead($Monitor2)
                        $Monitor3Res = GUICtrlRead($Monitor3)
                        $UserInputRes = GUICtrlRead($UserInput)
                        $DomainInputRes = GUICtrlRead($DomainInput)
                        $PasswordInputRes = GUICtrlRead($PasswordInput)

                        $RemRegSvc = 'SC \\' & $ServerNameRes & ' START "RemoteRegistry"'
                        $AppNameCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v ApplicationName /t REG_EXPAND_SZ /d "' & $AppNameRes & '"'
                        $AppOwnerCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v ApplicationOwner /t REG_Multi_SZ /d "' & $AppOwnerRes & '"'
                        $DeptNameCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v DeptName /t REG_EXPAND_SZ /d "' & $DeptNameRes & '"'
                        $LocationCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Location /t REG_EXPAND_SZ /d "' & $LocationRes & '"'
                        $Monitor1CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_1 /t REG_EXPAND_SZ /d "' & $Monitor1Res & '"'
                        $Monitor2CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_2 /t REG_EXPAND_SZ /d "' & $Monitor2Res & '"'
                        $Monitor3CMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Monitor_3 /t REG_EXPAND_SZ /d "' & $Monitor3Res & '"'
                        $PurposeCMD = 'REG ADD \\' & $ServerNameRes & '\HKLM\SOFTWARE\Inventory /f /v Purpose /t REG_EXPAND_SZ /d "' & $PurposeRes & '"'

                    ;Begin Write Registry Keys
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $RemRegSvc)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $AppNameCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $AppOwnerCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $DeptNameCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $LocationCMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor1CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor2CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $Monitor3CMD)
                        RunAsWait($UserInputRes, $DomainInputRes, $PasswordInputRes, 1, @ComSpec & " /c " & $PurposeCMD)
                    ;End Write Registry Keys

                    ;Begin Registry Key Verification
                        IF @CPUArch = "X86" Then
                            $AppNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationName")
                            $AppOwnerCurrent = RegRead("HKLM\SOFTWARE\Inventory", "ApplicationOwner")
                            $LocationCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Location")
                            $PurposeCurrent = RegRead("HKLM\SOFTWARE\Inventory", "Purpose")
                            $DeptNameCurrent = RegRead("HKLM\SOFTWARE\Inventory", "DeptName")
                            $Monitor1Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_1")
                            $Monitor2Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_2")
                            $Monitor3Current = RegRead("HKLM\SOFTWARE\Inventory", "Monitor_3")
                        Else
                            $AppNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationName")
                            $AppOwnerCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "ApplicationOwner")
                            $LocationCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Location")
                            $PurposeCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "Purpose")
                            $DeptNameCurrent = RegRead("HKLM64\SOFTWARE\Inventory", "DeptName")
                            $Monitor1Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_1")
                            $Monitor2Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_2")
                            $Monitor3Current = RegRead("HKLM64\SOFTWARE\Inventory", "Monitor_3")
                        EndIf


                        $FormComplet = GUICreate("CMG Server Registry Entries", 498, 372, 310, 124)
                        GUISetIcon("C:\Users\kpoling\Pictures\Icons\Registry.ico", -1)
                        $Label1 = GUICtrlCreateLabel("Verify Registry Keys:", 160, 16, 181, 24)
                        GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
                        $ServerNameCompLabel = GUICtrlCreateLabel("ServerName", 80, 59, 69, 17)
                        $AppNameCompLabel = GUICtrlCreateLabel("Application Name:", 59, 83, 90, 17)
                        $AppOwnerCompLabel = GUICtrlCreateLabel("Application Owner:", 58, 107, 93, 17)
                        $DeptNameCompLabel = GUICtrlCreateLabel("Department Name:", 57, 131, 93, 17)
                        $LocCompLabel = GUICtrlCreateLabel("Location of Server:", 56, 155, 94, 17)
                        $PurpCompLabel = GUICtrlCreateLabel("Purpose of Server:", 57, 179, 92, 17)
                        $Monitor1CompLabel = GUICtrlCreateLabel("Monitor 1:", 99, 203, 51, 17)
                        $Monitor2CompLabel = GUICtrlCreateLabel("Monitor 2:", 99, 227, 51, 17)
                        $Monitor3CompLabel = GUICtrlCreateLabel("Monitor 3:", 99, 251, 51, 17)
                        $ServerNameComp = GUICtrlCreateInput(@COMPUTERNAME, 160, 56, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $AppNameComp = GUICtrlCreateInput($AppNameCurrent, 160, 80, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $AppOwnerComp = GUICtrlCreateInput($AppOwnerCurrent, 160, 104, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $DeptNameComp = GUICtrlCreateInput($DeptNameCurrent, 160, 128, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $LocationComp = GUICtrlCreateInput($LocationCurrent, 160, 152, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $PurposeComp = GUICtrlCreateInput($PurposeCurrent, 160, 176, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor1Comp = GUICtrlCreateInput($Monitor1Current, 160, 200, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor2Comp = GUICtrlCreateInput($Monitor2Current, 160, 224, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $Monitor3Comp = GUICtrlCreateInput($Monitor3Current, 160, 248, 217, 21)
                        GUICtrlSetState(-1, $GUI_DISABLE)
                        $BackButton = GUICtrlCreateButton("Go Back", 160, 304, 75, 25)
                        GUICtrlSetState(-1, $GUI_ENABLE)
                        $DoneButton = GUICtrlCreateButton("Exit", 260, 304, 75, 25, $BS_DEFPUSHBUTTON)
                        GUISetState(@SW_SHOW)

                        While 1
                            $nMsg = GUIGetMsg()
                            Switch $nMsg
                                Case $BackButton
                                    GUISetState(@SW_HIDE,$FormComplet)
                                    GUISetState(@SW_HIDE,$credform)
                                    exitloop 2                          ; <------------------------  you were stuck in second nested while loop
                                Case $GUI_EVENT_CLOSE
                                    Exit
                                Case $DoneButton
                                    Exit

                            EndSwitch
                        WEnd
                        ;End Registry Key Verification


                        ; Exit                                          ;   <----  this has no effect, it never gets executed

                    Case $CredCancel
                        Exit

                EndSwitch
            WEnd



        Case $Cancel
            Exit
    EndSwitch
 WEnd

You do not need to issue GuiSetState() till after you have created all controls relevant to the current gui, as llewxam observed.

While your use of nested while...wend loops is technically possible, it makes trouble shooting and maintenance a nightmare.  I would encourage you to take a step back and define your task in terms of function / flow and re-organize your code.  At a glance, I would say that each gui should be a separate function. 

Good Luck,

kylomas

edit: additional info

1. - don't use a hotkey for the enter key, use an accelerator key (see the Help file)

2. - the function pointed to by the hotkey does not exist

3. - It is possible to do what you want using one gui and enabling / disabling controls.  Just something to consider.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Pretty much everybody that programs starts out writing code that just basically flows from top to bottom with a few "either this or that branches" and "repeat this a few times" sprinkled in the middle of that flow.  At some point, it becomes impractical to continue doing so, and then the programmer learns to break up their program using functions/objects/whatevers.

You are at that point.

Take your code and start breaking it into functional bits.  Think about how to remove redundancies, and how to write functions/sub routines that perform a task that can be called from multiple places.  Instead of repeating code, simply call that function when needed.

Here's a little bit that can jumpstart you:

$AppNameCurrent = ReadRegVal("ApplicationName")
$AppOwnerCurrent = ReadRegVal("ApplicationOwner")
...

Func ReadRegVal($sKey)
  Local $arch
  If @CPUArch = "X86" Then
    $arch = "HKLM"
  Else
    $arch = "HKLM64"
  EndIf
  Return RegRead($arch & "\SOFTWARE\Inventory", $sKey)
EndFunc
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites

To continue the thought - once you do that you will see that you don't need a way to "go back to the beginning", because you will never have left there in the first place. :)


How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites

To continue the thought - once you do that you will see that you don't need a way to "go back to the beginning", because you will never have left there in the first place. :)

 Man... That is deep....  I feel like it's The Matrix.  :)  Thanks everyone for the kick in the right direction!

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