Jump to content
Sign in to follow this  
Elephant007

Looking for some advice to shorten/cleanup script

Recommended Posts

Elephant007

Lengthy script that I need some help cleaning up, there are a lot of repetitiveness in the script and I have no idea how to make it shorter if it can be made shorter which I'm sure it can I just don't know how

I'm not asking for someone to rewrite the whole thing, unless you want to, I'm just asking for some guidance on how to shorten it...

I tried posting the script and my browser crashed, so instead I'm going to provide it as an attachment. It requires you to be using it from a domain, I removed that part so you can run it on your local computer

Your help is greatly appreciated!

Removed File

Thanks for everyone's help

Melba23 provided me with a great solution

Edited by Elephant007

Share this post


Link to post
Share on other sites
PhoenixXL

your code is really very badly written [never mind]

never use radio or checkboxes to fire an event,

use a button instead

In your case the button gets greyed before even using

  • Like 1

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

What a nightmare of a script - it must have been one hell of a job to write and will be even worse to update and maintain! :o

Perhaps unsurprisingly, I would do it very differently. Firstly I would put all the required data into an ini file - just save this as "Data.ini" in the same folder as the script:

[Campus]
Earlies=0
Elementary=0
Middle=0
High=0
Non-Instructional=0

[Earlies]
Crockett=107
Locust=117
Woodson=125

[Elementary]
Austin=102
Bowie=???
Johnston=113
Martinez=155
Reagan=???
Ward=150
Bassetti=153
Dyess=108
Lee=116
McMurry=080
Taylor=121
Bonham=103
Jackson=112
Long=118
Ortiz=152

[Middle]
Clack=047
Madison=044
Craig=048
Mann=045

[High]
Abilene=001
Cooper=002
Woodson=008
ATEMS=010
Holland=009

[Non-Instructional]
Admin Bldg=201
Planetarium=131
Tech Center=200
Transport=008
Maintenance=251
Purchasing=238
Tech Support=102
Warehouse=238

[Department]
Athletics=A
Communications=O
Fine Arts=N
Maintenance=M
Bilingual=B
Curriculum/Instruction=R
Health=H
Technology=T
Child Nutrition=C
Finance/Payroll=F
HR/Benefits= R
Warehouse=W

[Room]
Cafe=F
Counselor=U
Lab=L
MILE Cart=M
Portable=P
Classroom=C
Gym=G
LRC=R
Office=O

[User]
Admin=A
LRC=L
Secretary=E
Warehouse=W
Aide=D
Maintenance= M
Special Ed=F
Band/Music=B
Nurses=N
Student=S
Coach=G
Office=o
Teacher=T
Counselor=C
Principals=P
Technology=H

Now you can easily add, remove or amend the data without having to search for every instance within your script. ;)

Now we can write some code which is also a lot easier to maintain and much easier to follow:

#region ; Includes

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <ProgressConstants.au3>

#endregion

#region ; Setup

; Declare Global variables
Global $cButton_Comp, $cButton_Room_Inits, $cProgess_Remote, $cCombo_Type
Global $cInput_Comp, $cInput_Room_Inits, $cInput_Remote, $cInput_Name_1

#endregion

; Run function
Local $sComputer_Name = Menu01()
If @error Then
    MsgBox(0, "Ooops", "[X] pressed")
Else
    MsgBox(0, "All done", "Renamed to " & $sComputer_Name)
EndIf
; Exit
Exit

Func Menu01()

    #region ; Read data

    $sIni = "Data.ini"

    ; Read the ini section
    Local $aCampus = IniReadSection($sIni, "Campus")
    ; Convert into a string to fill the combo
    Local $sCampus = ""
    For $i = 1 To $aCampus[0][0]
        $sCampus &= "|" & $aCampus[$i][0]
    Next

    ; And do the same for the other sections
    Local $aEarlies = IniReadSection($sIni, "Earlies")
    Local $sEarlies = ""
    For $i = 1 To $aEarlies[0][0]
        $sEarlies &= "|" & $aEarlies[$i][0]
    Next

    Local $aElementary = IniReadSection($sIni, "Elementary")
    Local $sElementary = ""
    For $i = 1 To $aElementary[0][0]
        $sElementary &= "|" & $aElementary[$i][0]
    Next

    Local $aMiddle = IniReadSection($sIni, "Middle")
    Local $sMiddle = ""
    For $i = 1 To $aMiddle[0][0]
        $sMiddle &= "|" & $aMiddle[$i][0]
    Next

    Local $aHigh = IniReadSection($sIni, "High")
    Local $sHigh = ""
    For $i = 1 To $aHigh[0][0]
        $sHigh &= "|" & $aHigh[$i][0]
    Next

    Local $aNonInstructional = IniReadSection($sIni, "Non-Instructional")
    Local $sNonInstructional = ""
    For $i = 1 To $aNonInstructional[0][0]
        $sNonInstructional &= "|" & $aNonInstructional[$i][0]
    Next

    Local $aDepartment = IniReadSection($sIni, "Department")
    Local $sDepartment = ""
    For $i = 1 To $aDepartment[0][0]
        $sDepartment &= "|" & $aDepartment[$i][0]
    Next

    Local $aRoom = IniReadSection($sIni, "Room")
    Local $sRoom = ""
    For $i = 1 To $aRoom[0][0]
        $sRoom &= "|" & $aRoom[$i][0]
    Next

    Local $aUser = IniReadSection($sIni, "User")
    Local $sUser = ""
    For $i = 1 To $aUser[0][0]
        $sUser &= "|" & $aUser[$i][0]
    Next

    #endregion ; Read data

    #region ; Create GUI

    ; Create GUI - all items created and hidden until ready
    Local $hGUI = GUICreate("Test", 500, 560)

    GUICtrlCreateLabel("Campus Type", 10, 15, 200, 20)
    $cCombo_Type = GUICtrlCreateCombo("", 10, 40, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sCampus)

    Local $cLabel_Location = GUICtrlCreateLabel("Location", 10, 75, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Location = GUICtrlCreateCombo("", 10, 100, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Dept = GUICtrlCreateLabel("", 10, 135, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Room_Dept = GUICtrlCreateCombo("", 10, 160, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Inits = GUICtrlCreateLabel("", 10, 195, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Room_Inits = GUICtrlCreateInput("", 110, 195, 50, 20)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Room_Inits = GUICtrlCreateButton("Accept", 175, 195, 100, 20)
    GUICtrlSetState(-1, BitOr($GUI_HIDE, $GUI_DISABLE))

    Local $cLabel_User = GUICtrlCreateLabel("User", 10, 230, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_User = GUICtrlCreateCombo("", 10, 255, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sUser)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Comp = GUICtrlCreateLabel("Computer Number", 10, 290, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Comp = GUICtrlCreateInput("", 110, 290, 50, 20)
    GUICtrlSetLimit(-1, 2)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Comp = GUICtrlCreateButton("Accept", 175, 290, 100, 20)
    GUICtrlSetState(-1, BitOr($GUI_HIDE, $GUI_DISABLE))

    GUIStartGroup()
    Local $cRadio_Local = GUICtrlCreateRadio(" Local Computer", 10, 380, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cRadio_Remote = GUICtrlCreateRadio(" Remote Computer", 10, 410, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Remote = GUICtrlCreateInput("", 30, 430, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Remote = GUICtrlCreateButton("Accept", 30, 460, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $sLabel_Checking = GUICtrlCreateLabel("Checking Computer" & @CRLF & "Account Type", 140, 460, 200, 40)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Rename = GUICtrlCreateButton("", 260, 380, 200, 100)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Remote = GUICtrlCreateLabel("", 10, 500, 480, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cProgess_Remote = GUICtrlCreateProgress(10, 530, 480, 20, $PBS_MARQUEE)
    GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50)
    GUICtrlSetState(-1, $GUI_HIDE)

    ; These are created last as we never want to hide them
    GUICtrlCreateLabel("Computer Name", 10, 340, 100, 20)
    GUICtrlCreateLabel("-", 150, 340, 10, 20)
    GUICtrlCreateLabel("-", 180, 340, 10, 20)
    GUICtrlCreateLabel("-", 260, 340, 10, 20)
    $cInput_Name_1 = GUICtrlCreateInput("", 110, 340, 40, 20, $ES_READONLY)
    $cInput_Name_2 = GUICtrlCreateInput("", 160, 340, 20, 20, $ES_READONLY)
    $cInput_Name_3 = GUICtrlCreateInput("", 190, 340, 70, 20, $ES_READONLY)
    $cInput_Name_4 = GUICtrlCreateInput("", 270, 340, 20, 20, $ES_READONLY)
    $cInput_Name_5 = GUICtrlCreateInput("", 290, 340, 40, 20, $ES_READONLY)

    GUISetState()

    #endregion

    ; Register the input change message to control what happen in the inputs
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

    #region ;Main loop

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($hGUI)
                Return SetError(1, 0, 0)
            Case $cCombo_Type
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Dept, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Location, $GUI_SHOW)
                GUICtrlSetState($cCombo_Location, $GUI_SHOW)
                ; Set the next combo depending on what was selected
                Switch GUICtrlRead($cCombo_Type)
                    Case "Earlies"
                        GUICtrlSetData($cCombo_Location, $sEarlies)
                    Case "Elementary"
                        GUICtrlSetData($cCombo_Location, $sElementary)
                    Case "Middle"
                        GUICtrlSetData($cCombo_Location, $sMiddle)
                    Case "High"
                        GUICtrlSetData($cCombo_Location, $sHigh)
                    Case "Non-Instructional"
                        GUICtrlSetData($cCombo_Location, $sNonInstructional)
                EndSwitch

            Case $cCombo_Location
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Dept, $GUI_SHOW)
                GUICtrlSetState($cCombo_Room_Dept, $GUI_SHOW)
                ; Read the combos
                $sLocation = GUICtrlRead($cCombo_Location)
                $sType = GUICtrlRead($cCombo_Type)
                ; Fill in the computer name section by reading the ini file by reading the ini file
                GUICtrlSetData($cInput_Name_1, IniRead($sIni, $sType, $sLocation, "###"))
                ; Set the next combo depending on what was selected
                Switch $sType
                    Case "Non-Instructional"
                        GUICtrlSetData($cLabel_Room_Dept, "Department")
                        GUICtrlSetData($cCombo_Room_Dept, $sDepartment)
                    Case Else
                        GUICtrlSetData($cLabel_Room_Dept, "Room Type")
                        GUICtrlSetData($cCombo_Room_Dept, $sRoom)
                EndSwitch

            Case $cCombo_Room_Dept
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 1)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Inits, $GUI_SHOW)
                GUICtrlSetState($cInput_Room_Inits, $GUI_SHOW)
                GUICtrlSetData($cInput_Room_Inits, "")
                GUICtrlSetState($cButton_Room_Inits, $GUI_SHOW)
                ; Read the combo
                $sRoom_Dept = GUICtrlRead($cCombo_Room_Dept)
                ; Depending on selection
                Switch $sType
                    Case "Non-Instructional"
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Department", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "User Initials")
                    Case Else
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Room", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "Room Number")
                EndSwitch
                ; Set focus on the input
                GUICtrlSetState($cInput_Room_Inits, $GUI_FOCUS)

            Case $cButton_Room_Inits
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_3, GUICtrlRead($cInput_Room_Inits))
                GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                ; Show the next level down
                GUICtrlSetState($cLabel_User, $GUI_SHOW)
                GUICtrlSetState($cCombo_User, $GUI_SHOW)

            Case $cCombo_User
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Comp, 3)
                ; Show the next level down
                GUICtrlSetState($cLabel_Comp, $GUI_SHOW)
                GUICtrlSetState($cInput_Comp, $GUI_SHOW)
                GUICtrlSetData($cInput_Comp, "")
                GUICtrlSetState($cButton_Comp, $GUI_SHOW)
                ; Read the combo
                $sUser = GUICtrlRead($cCombo_User)
                ; Fill in the computer name section by reading the ini file
                GUICtrlSetData($cInput_Name_4, IniRead($sIni, "User", $sUser, "###"))
                ; Set focus to the input
                GUICtrlSetState($cInput_Comp, $GUI_FOCUS)

            Case $cButton_Comp
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_5, GUICtrlRead($cInput_Comp))
                GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                ; Show the next level down
                GUICtrlSetState($cRadio_Local, $GUI_SHOW)
                GUICtrlSetState($cRadio_Remote, $GUI_SHOW)

            Case $cRadio_Local
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                $sName = GUICtrlRead($cInput_Name_1) & "-" & GUICtrlRead($cInput_Name_2) & "-" & GUICtrlRead($cInput_Name_3) & "-" & GUICtrlRead($cInput_Name_4) & GUICtrlRead($cInput_Name_5)
                GUICtrlSetData($cButton_Rename, "Change Local Name Now!")
                ; Show the Rename button
                GUICtrlSetState($cButton_Rename, $GUI_SHOW)

            Case $cRadio_Remote
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                ; Show the required controls
                GUICtrlSetState($cInput_Remote, BitOr($GUI_SHOW, $GUI_FOCUS))
                GUICtrlSetData($cInput_Remote, "")
                GUICtrlSetState($cButton_Remote, $GUI_SHOW)

            Case $cButton_Remote
                GUICtrlSetState($cLabel_Remote, $GUI_SHOW)
                ;RunWait("Notepad.exe")
                GUICtrlSetData($cButton_Rename, "Change Remote Name Now!")
                ; Show the Rename button
                GUICtrlSetState($cButton_Rename, $GUI_SHOW)

            Case $cButton_Rename
                If GUICtrlRead($cRadio_Local) = 1 Then
                    ; Code to rename
                    MsgBox(0, "Local", "Renaming to: " & $sName)
                Else
                    ; Show label and progress
                    GUICtrlSetState($cLabel_Remote, $GUI_SHOW)
                    GUICtrlSetState($cProgess_Remote, $GUI_SHOW)
                    ; Code to rename
                    MsgBox(0, "Remote", "Renaming to:" & $sName)
                EndIf
                ; Exit
                GUIDelete($hGUI)
                Return($sName)

        EndSwitch

    WEnd

    #endregion

EndFunc

Func _Clear_All_Below($cCID, $iIndex = 5)

    ; Force the "Accept" buttons to disabled
    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
    ; Hode all controls after the one passed
    For $i = $cCid To $cProgess_Remote
        GUICtrlSetState($i, $GUI_HIDE)
    Next
    ; Empty the computer name inputs as required
    For $i = $iIndex To 4
        GUICtrlSetData($cInput_Name_1 + $i, "")
    Next

EndFunc   ;==>_Clear_All_Below

Func _WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $cInput_Room_Inits
                $sData = GUICtrlRead($cInput_Room_Inits)
                If GUICtrlRead($cCombo_Type) = "Non-Instructional" Then
                    ; Need only uppercase alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alpha:]]", ""))
                Else
                    ; Need only digits
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:digit:]]", ""))
                EndIf
                GUICtrlSetData($cInput_Room_Inits, $sData)
                ; And we need 4 of them
                If StringLen($sData) = 4 Then
                    ; Enable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_ENABLE)
                Else
                    ; Disable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                EndIf
            Case $cInput_Comp
                ; Need 2 digits only
                $sData = GUICtrlRead($cInput_Comp)
                $sData = StringRegExpReplace(GUICtrlRead($cInput_Comp), "[^[:digit:]]", "")
                GUICtrlSetData($cInput_Comp, $sData)
                If StringLen($sData) = 2 Then
                    GUICtrlSetState($cButton_Comp, $GUI_ENABLE)
                Else
                    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                EndIf
            Case $cInput_Remote
                ; No idea what you want here
        EndSwitch

    EndIf
EndFunc

This gives me the same results as your script when I test it - although I have not been through every possible combination. I have commented the script liberally so I hope you can follow it without problem, but please do ask if you have any questions. :)

And thanks for filling in an empty morning while the wife had friends around for coffee. :D

M23

Edited by Melba23
Tinkering!
  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

PheonixXL; Nightmare of a script huh? Wouldn't doubt it at all, this is why I'm asking for some help! HAHA I was hesitant at first to post it, then thought, this is a help forum so what the heck.. haha, thanks for being gentle though. The button that grays out is used as a "back" feature to get back to the previous menu. Thank you for your advice

Melba23; Wow, just wow, thank you for taking the time to write what you did... It's cool that the data can be called from an ini file, could I essentially add the ini using FileInstall()? Thank you so much for laying the foundation of this program, I can take it from here and hopefully keep it as clean as you gave it to me...

Thank you everyone for looking and giving me direction on how you best thing to solve this messy nightmare!

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

Why do you need to FileInstall the data? Will lots of users be running this? :huh:

If that is indeed the case then you could always declare the relevant arrays to hold the data within the script itself, like this:

Local $aEarlies[4][2] = [[3, 0], _
                         ["Crockett", 107], _
                         ["Locust",   117], _
                         ["Woodson",  125]]
For $i = 1 To $aEarlies[0][0]
    $sEarlies &= "|" & $aEarlies[$i][0]
Next

It would mean another code change where we extract the matching computer codename sections, but that is easy to do. What do you think? :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

Elephant007,

Why do you need to FileInstall the data? Will lots of users be running this? :huh:

If that is indeed the case then you could always declare the relevant arrays to hold the data within the script itself, like this:

Local $aEarlies[4][2] = [[3, 0], _
["Crockett", 107], _
["Locust", 117], _
["Woodson", 125]]
For $i = 1 To $aEarlies[0][0]
$sEarlies &= "|" & $aEarlies[$i][0]
Next

It would mean another code change where we extract the matching computer codename sections, but that is easy to do. What do you think? :)

M23

Yes we have 10,000 computers on our domain and we would like for users in specific security groups to be able to change a computer when it is moved to a different location. Our plan is to have this program available on all 10,000 computers so at anytime any computer that is moved can be renamed to try to help identify where the computer is located

Thank you for all the help you given me, you've made my headache go away! I should also let you know that I plan to include netdom and dsquery in the script too... makes it a little meater but I can't guarantee that all computers will have the required files to rename the computer on active directory

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

Then I would definitely go for FileInstalling the ini file - then all you need to do to update the various elements would be to amend/overwrite that single file. :)

Delighted I could help - as I said it helped pass a morning when I was confined to my study. Do come back if you run into any problems with it. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

Excellent! One last question I have for now. It's possible that the room number can be alpha and numeric. How can I enable it so that the room number can be alphanumeric and not allow any special characters?

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

That is easy (or at least it is when you know how)! ;)

In the _WM_COMMAND function (right at the end) change this: :)

Else
    ; Need only digits
    $sData = StringUpper(StringRegExpReplace($sData, "[^[:digit:]]", ""))
EndIf

To this

Else
    ; Need digits or alpha
    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", ""))
EndIf

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

Elephant007,

That is easy (or at least it is when you know how)! ;)

In the _WM_COMMAND function (right at the end) change this: :)

Else
; Need only digits
$sData = StringUpper(StringRegExpReplace($sData, "[^[:digit:]]", ""))
EndIf

To this

Else
; Need digits or alpha
$sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", ""))
EndIf

M23

You make it look so easy.. again I can't thank you enough for all the help you've provided me.. basically you've taken my idea and made it come true!

I was wondering if you would like to help me with this part too because there was more of the program that I built other than what I uploaded at the start of this thread.

This part I'm giving you has comments in it to try to help you understand my intentions... Part of it happens before the main program you worked on and the other half happens afterwards

I am unsure if you'll be able to actually run the script because it requires a domain to run essentially... I think you can figure out how to comment them out and then I can re-enable them later...

Hope you can make sense of my scrambled brain...

MoreHelpPlease.au3

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

Here is the amended file. I have tested it as far as I am able by hard-coding the various return values from the network apps - over to you for some more rigorous testing: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <ComboConstants.au3>
#include <TokenGroup.au3>
#include <File.au3>

;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

; Declare as Global here, not inside a function
Global $Username, $Password, $GOButton
Global $cButton_Comp, $cButton_Room_Inits, $cProgress_Renaming, $cCombo_Type
Global $cInput_Comp, $cInput_Room_Inits, $cInput_Remote, $cInput_Name_1

; Now not needed
;Global $ComputerNamingLizardLocalRemote, $ComputerNamingLizardLocal

;Checks to see if the file exists and then deletes it
FileDelete('%TEMP%ServersList')

Run('taskkill.exe /IM AISD-411*', '', @SW_HIDE)

;Checks to see if this is running in Windows PE while imaging a computer from a thumb drive
If FileExists('X:WindowsSystem32Sysprep') Then

    ;$ImagingComputer = '1' ; Now not needed

    Menu01(0) ; Pass the required state to the function directly - in this case 0 = "Imaging only" <<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; What do you want to do here? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; At the moment you just continue with the rest of the script which I assume you do not want
    ; Surely you want to exit now as the renaming has been done?
    ; I suggest you exit directly from the Menu01 function and that is what I have coded

Else

    ; Might as well put this here! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ;GUI for user to input username and password to check if they have network access
    ComputerNamingLizardCreds()

EndIf

;Checks to see if the supplied user credentials is a memeber of a specific network security group
;If the user is a memeber of 'Scripts Computer Naming Lizard Local & Remote' then they are able to change a local or remote computer
;If the user is a memeber of 'Scripts Computer Naming Lizard Local' then they are able to ONLY change local computers, REMOTE and LOCAL options never show, just the CHANGE LOCAL NAME NOW button

; There is no point in calling thisfunction here as we never reach this point <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Either we exit from the Creds function if creds cannot be verified or from the Menu01 function when it completes or fails
; CheckPermissions()

; #########################################################################

Func Menu01($iToken)

    Local $sIni = "Data.ini", $vMsg

    ; Read the ini section
    Local $aCampus = IniReadSection($sIni, "Campus")
    ; Convert into a string to fill the combo
    Local $sCampus = ""
    For $i = 1 To $aCampus[0][0]
        $sCampus &= "|" & $aCampus[$i][0]
    Next

    ; And do the same for the other sections
    Local $aEarlies = IniReadSection($sIni, "Earlies")
    Local $sEarlies = ""
    For $i = 1 To $aEarlies[0][0]
        $sEarlies &= "|" & $aEarlies[$i][0]
    Next

    Local $aElementary = IniReadSection($sIni, "Elementary")
    Local $sElementary = ""
    For $i = 1 To $aElementary[0][0]
        $sElementary &= "|" & $aElementary[$i][0]
    Next

    Local $aMiddle = IniReadSection($sIni, "Middle")
    Local $sMiddle = ""
    For $i = 1 To $aMiddle[0][0]
        $sMiddle &= "|" & $aMiddle[$i][0]
    Next

    Local $aHigh = IniReadSection($sIni, "High")
    Local $sHigh = ""
    For $i = 1 To $aHigh[0][0]
        $sHigh &= "|" & $aHigh[$i][0]
    Next

    Local $aNonInstructional = IniReadSection($sIni, "Non-Instructional")
    Local $sNonInstructional = ""
    For $i = 1 To $aNonInstructional[0][0]
        $sNonInstructional &= "|" & $aNonInstructional[$i][0]
    Next

    Local $aDepartment = IniReadSection($sIni, "Department")
    Local $sDepartment = ""
    For $i = 1 To $aDepartment[0][0]
        $sDepartment &= "|" & $aDepartment[$i][0]
    Next

    Local $aRoom = IniReadSection($sIni, "Room")
    Local $sRoom = ""
    For $i = 1 To $aRoom[0][0]
        $sRoom &= "|" & $aRoom[$i][0]
    Next

    Local $aUser = IniReadSection($sIni, "User")
    Local $sUser = ""
    For $i = 1 To $aUser[0][0]
        $sUser &= "|" & $aUser[$i][0]
    Next

    ; Create GUI - all items created and hidden until ready
    GUICreate("Computer Renaming Lizard", 500, 560)

    GUICtrlCreateLabel("Campus Type", 10, 15, 200, 20)
    $cCombo_Type = GUICtrlCreateCombo("", 10, 40, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sCampus)

    Local $cLabel_Location = GUICtrlCreateLabel("Location", 10, 75, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Location = GUICtrlCreateCombo("", 10, 100, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Dept = GUICtrlCreateLabel("", 10, 135, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Room_Dept = GUICtrlCreateCombo("", 10, 160, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Inits = GUICtrlCreateLabel("", 10, 195, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Room_Inits = GUICtrlCreateInput("", 110, 195, 50, 20)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Room_Inits = GUICtrlCreateButton("Accept", 175, 195, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    Local $cLabel_User = GUICtrlCreateLabel("User", 10, 230, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_User = GUICtrlCreateCombo("", 10, 255, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sUser)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Comp = GUICtrlCreateLabel("Computer Number", 10, 290, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Comp = GUICtrlCreateInput("", 110, 290, 50, 20)
    GUICtrlSetLimit(-1, 2)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Comp = GUICtrlCreateButton("Accept", 175, 290, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    GUIStartGroup()
    Local $cRadio_Local = GUICtrlCreateRadio(" Local Computer", 10, 380, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cRadio_Remote = GUICtrlCreateRadio(" Remote Computer", 10, 410, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Remote = GUICtrlCreateInput("", 30, 430, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Remote = GUICtrlCreateButton("Accept", 30, 460, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $sLabel_Checking = GUICtrlCreateLabel("Checking Computer" & @CRLF & "Account Type", 140, 460, 200, 40)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Rename = GUICtrlCreateButton("", 260, 380, 200, 100)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Renaming = GUICtrlCreateLabel("", 10, 500, 480, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cProgress_Renaming = GUICtrlCreateProgress(10, 530, 480, 20, $PBS_MARQUEE)
    GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50)
    GUICtrlSetState(-1, $GUI_HIDE)

    ; These are created last as we never want to hide them
    GUICtrlCreateLabel("Computer Name", 10, 340, 100, 20)
    GUICtrlCreateLabel("-", 150, 340, 10, 20)
    GUICtrlCreateLabel("-", 180, 340, 10, 20)
    GUICtrlCreateLabel("-", 260, 340, 10, 20)
    $cInput_Name_1 = GUICtrlCreateInput("", 110, 340, 40, 20, $ES_READONLY)
    Local $cInput_Name_2 = GUICtrlCreateInput("", 160, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_3 = GUICtrlCreateInput("", 190, 340, 70, 20, $ES_READONLY)
    Local $cInput_Name_4 = GUICtrlCreateInput("", 270, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_5 = GUICtrlCreateInput("", 290, 340, 40, 20, $ES_READONLY)

    ; Create dummy to fire Local rename <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLocal_Dummy = GUICtrlCreateDummy()

    GUISetState()

    #endregion ; Create GUI

    ; Register the input change message to control what happen in the inputs
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Menu01")

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ;GUIDelete($hGUI) ; No need as we exit directly
                 Exit

            Case $cCombo_Type
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Dept, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Location, $GUI_SHOW)
                GUICtrlSetState($cCombo_Location, $GUI_SHOW)
                ; Set the next combo depending on what was selected
                Switch GUICtrlRead($cCombo_Type)
                    Case "Earlies"
                        GUICtrlSetData($cCombo_Location, $sEarlies)
                    Case "Elementary"
                        GUICtrlSetData($cCombo_Location, $sElementary)
                    Case "Middle"
                        GUICtrlSetData($cCombo_Location, $sMiddle)
                    Case "High"
                        GUICtrlSetData($cCombo_Location, $sHigh)
                    Case "Non-Instructional"
                        GUICtrlSetData($cCombo_Location, $sNonInstructional)
                EndSwitch

            Case $cCombo_Location
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Dept, $GUI_SHOW)
                GUICtrlSetState($cCombo_Room_Dept, $GUI_SHOW)
                ; Read the combos
                Local $sLocation = GUICtrlRead($cCombo_Location)
                Local $sType = GUICtrlRead($cCombo_Type)
                ; Fill in the computer name section by reading the ini file by reading the ini file
                GUICtrlSetData($cInput_Name_1, IniRead($sIni, $sType, $sLocation, "###"))
                ; Set the next combo depending on what was selected
                Switch $sType
                    Case "Non-Instructional"
                        GUICtrlSetData($cLabel_Room_Dept, "Department")
                        GUICtrlSetData($cCombo_Room_Dept, $sDepartment)
                    Case Else
                        GUICtrlSetData($cLabel_Room_Dept, "Room Type")
                        GUICtrlSetData($cCombo_Room_Dept, $sRoom)
                EndSwitch

            Case $cCombo_Room_Dept
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 1)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Inits, $GUI_SHOW)
                GUICtrlSetState($cInput_Room_Inits, $GUI_SHOW)
                GUICtrlSetData($cInput_Room_Inits, "")
                GUICtrlSetState($cButton_Room_Inits, $GUI_SHOW)
                ; Read the combo
                Local $sRoom_Dept = GUICtrlRead($cCombo_Room_Dept)
                ; Depending on selection
                Switch $sType
                    Case "Non-Instructional"
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Department", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "User Initials")
                    Case Else
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Room", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "Room Number")
                EndSwitch
                ; Set focus on the input
                GUICtrlSetState($cInput_Room_Inits, $GUI_FOCUS)

            Case $cButton_Room_Inits
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_3, GUICtrlRead($cInput_Room_Inits))
                GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                ; Show the next level down
                GUICtrlSetState($cLabel_User, $GUI_SHOW)
                GUICtrlSetState($cCombo_User, $GUI_SHOW)

            Case $cCombo_User
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Comp, 3)
                ; Show the next level down
                GUICtrlSetState($cLabel_Comp, $GUI_SHOW)
                GUICtrlSetState($cInput_Comp, $GUI_SHOW)
                GUICtrlSetData($cInput_Comp, "")
                GUICtrlSetState($cButton_Comp, $GUI_SHOW)
                ; Read the combo
                $sUser = GUICtrlRead($cCombo_User)
                ; Fill in the computer name section by reading the ini file
                GUICtrlSetData($cInput_Name_4, IniRead($sIni, "User", $sUser, "###"))
                ; Set focus to the input
                GUICtrlSetState($cInput_Comp, $GUI_FOCUS)

            Case $cButton_Comp
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_5, GUICtrlRead($cInput_Comp))
                GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                ; Read complete name
                Local $LizardComputerName = GUICtrlRead($cInput_Name_1) & "-" & GUICtrlRead($cInput_Name_2) & "-" & GUICtrlRead($cInput_Name_3) & "-" & GUICtrlRead($cInput_Name_4) & GUICtrlRead($cInput_Name_5)
                ; Show the next level down depending on the token passed to the function
                Switch $iToken
                    Case 0
                        ; Imaging token passed
                        GUICtrlSetData($cButton_Rename, "Change Image Name Now!")
                        GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                    Case 1
                        ; Local only rename permission token passed - so act as if that radio was selected
                        ; Set the Local radio to checked and fire the dummy to run the event code ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        GUICtrlSetState($cRadio_Local, $GUI_CHECKED)
                        GUICtrlSendToDummy($cLocal_Dummy)
                    Case 2
                        ; Remote & Local rename permission token passed
                        GUICtrlSetState($cRadio_Local, $GUI_SHOW)
                        GUICtrlSetState($cRadio_Remote, $GUI_SHOW)
                EndSwitch

            Case $cRadio_Local, $cLocal_Dummy
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                GUICtrlSetData($cButton_Rename, "Change Local Name Now!")
                ; Show the Rename button
                GUICtrlSetState($cButton_Rename, $GUI_SHOW)

            Case $cRadio_Remote
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                ; Show the required controls
                GUICtrlSetState($cInput_Remote, BitOR($GUI_SHOW, $GUI_FOCUS))
                GUICtrlSetData($cInput_Remote, "")
                GUICtrlSetState($cButton_Remote, $GUI_SHOW)

            Case $cButton_Remote
                ; Set controls
                GUICtrlSetState($cInput_Remote, $GUI_DISABLE)
                GUICtrlSetState($cButton_Remote, $GUI_DISABLE)
                GUICtrlSetState($sLabel_Checking, $GUI_SHOW)
                GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                ;runs a DSQUERY to get names of servers and not allow the program to continue, we don't want servers renamed, this runs a dsquery from a specified location
                RunWait('cmd /c SpecifiedLocationdsquery.exe * "DC=domainname,DC=org" -limit 0 -filter "(&(OperatingSystem=*server*))" > %TEMP%ServersList', '', @SW_HIDE)
                Do
                    Sleep(1000)
                Until FileExists('%TEMP%ServersList')
                ; Hide label and progress
                GUICtrlSetState($sLabel_Checking, $GUI_HIDE)
                GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                ; $FileOpen = FileOpen('%TEMP%ServersList', 0) ; No need to open it to read it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                ; $sFile_Text = FileRead('%TEMP%ServersList') ; Just read it below <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                Local $String = StringInStr(FileRead('%TEMP%ServersList'), GUICtrlRead($cInput_Remote))
                If $String > 0 Then
                    ;FileClose($FileOpen) ; Now not opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    FileDelete('%TEMP%ServersList')
                    MsgBox(16, 'Remote Computer Error!', 'Computer Account Type Does Not Allow Changing Name')
                    ; You said the idea was not to continue if it was a server - so here seems a good point to exit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    Exit
                    ; And so there is no need for these <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ;GUICtrlSetData($NameRemoteComputerInput, '')
                    ;GUICtrlSetState($NameRemoteComputerInput, $GUI_ENABLE)
                    ;GUICtrlSetState($NameRemoteComputerCheckbox, $GUI_UNCHECKED + $GUI_ENABLE)
                    ;GUICtrlSetState($PleaseWait, $GUI_HIDE)
                Else
                    ; $String = 0 so not a server
                    GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                    ; Show the Rename button
                    GUICtrlSetData($cButton_Rename, "Change Remote Name Now!")
                    GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                EndIf

            Case $cButton_Rename
                ; Are we imaging
                If $iToken = 0 Then
                    ;Unable to get this working with sysprep at the moment, it does change the line I want it to change it's just that Sysprep still names the computer whatever it desires! HAHA
                    GUICtrlSetData($cLabel_Renaming, 'Setting Computer Name To: ' & $LizardComputerName)
                    ; Disable all controls
                    For $i = $cCombo_Type To $cButton_Rename
                        GUICtrlSetState($i, $GUI_DISABLE)
                    Next

                    _FileWriteToLine('E:WindowsSystem32sysprepAISDUnattend.Enterprise.x86.xml', 31, '<ComputerName>' & $LizardComputerName & '</ComputerName>', 0)

                    MsgBox(0, "Imaging Complete", "Computer Name set to:" & $LizardComputerName)
                    Exit

                Else ; It is a Local or Remote rename
                    ; Was local selected
                    If GUICtrlRead($cRadio_Local) = 1 Then
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Local Computer Name From: ' & @ComputerName & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomLocalComputer = RunWait('SpecifiedLocationnetdom.exe renamecomputer ' & @ComputerName & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:10', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;Below are possible error codes that netdom will pass, I would like for these to popup a msgbox indicating errors. Error 0 is success
                        Switch $NetdomLocalComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                ; No need to clear anything, we will just exit when the above MsgBox is cleared
                                Exit
                                ;GUICtrlSetState($ProgressBar, $GUI_HIDE)
                                ;GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                                ;GUICtrlSetState($cButton_Rename, $GUI_DISABLE)
                                ;GUICtrlSetState($ExitNamingLizard, $GUI_SHOW)
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomLocalComputer
                                    Case 53
                                        $vMsg = 'Local Computer Not Found'
                                    Case 87
                                        $vMsg = 'Local Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Local Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so re-enable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    Else ; Remote was selected
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Remote Computer Name From: ' & GUICtrlRead($cInput_Remote) & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomRemoteComputer = RunWait('cmd /c SpecifiedLocationnetdom.exe renamecomputer ' & GUICtrlRead($cInput_Remote) & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:05', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;again showing error codes passed from the netdom Executable
                        Switch $NetdomRemoteComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                ; No need to clear anything, we will just exit when the above MsgBox is cleared
                                Exit
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomRemoteComputer
                                    Case 53
                                        $vMsg = 'Remote Computer Not Found'
                                    Case 87
                                        $vMsg = 'Remote Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Remote Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes" and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so reenable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    EndIf
                EndIf
        EndSwitch
    WEnd

EndFunc   ;==>Menu01

Func _Clear_All_Below($cCID, $iIndex = 5)

    ; Force the "Accept" buttons to disabled
    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
    ; Hide all controls after the one passed
    For $i = $cCID To $cProgress_Renaming
        GUICtrlSetState($i, $GUI_HIDE)
    Next
    ; Empty the computer name inputs as required
    For $i = $iIndex To 4
        GUICtrlSetData($cInput_Name_1 + $i, "")
    Next

EndFunc   ;==>_Clear_All_Below

Func ComputerNamingLizardCreds()

    Local $CNLRA = GUICreate("Computer Naming Lizard RunAs", 320, 150) ; Only needs to be in Local scope

    $Username = GUICtrlCreateInput('', 80, 30, 220, 20)
    GUICtrlSetLimit(-1, 5)
    $Password = GUICtrlCreateInput('', 80, 60, 220, 20, $ES_PASSWORD)
    GUICtrlSetLimit(-1, 8)
    GUICtrlSetState($Password, $GUI_DISABLE)
    GUICtrlCreateLabel('Username and Password to RunAs', 5, 10, 200, 20)
    GUICtrlCreateLabel('Username:', 20, 32.5, 50, 20)
    GUICtrlCreateLabel('Password:', 20, 62.5, 50, 20)

    $GOButton = GUICtrlCreateButton('GO!', 110, 90, 100, 40)
    GUICtrlSetState($GOButton, BitOR($GUI_DISABLE, $GUI_DEFBUTTON)) ; Always use BitOR to combine styles <<<<<<<<<<<<<<<<<

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Creds")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                MsgBox(16, 'Error', 'Renaming Aborted')
                Exit ; I take that using the [X] means that you should exit the whole script <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $GOButton
                ;runs as user supplied credentials, ComputerNamingLizardCredentialsCheck.exe just opens and closes notepad.exe

                Local $CredCheck = RunAs(GUICtrlRead($Username), 'domainname', GUICtrlRead($Password), 0, 'networklocationComputerNamingLizardCredentialsCheck.exe', '', @SW_HIDE)

                If $CredCheck = 0 Then
                    MsgBox(48, 'Error', 'Incorrect username and/or password')
                    ;GUICtrlSetState($GOButton, $GUI_ENABLE)
                    ;GUIDelete($CNLRA)
                    ; ComputerNamingLizardCreds()  ; Very bad use of recursion here !!!!!!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ; I would just continue the loop until the correct username/password is entered or dialog is closed via the [X]
                    ; So we need to do this to reset the dialog
                    GUICtrlSetData($Username, "")
                    GUICtrlSetData($Password, "")
                    GUICtrlSetState($Password, $GUI_DISABLE)
                    GUICtrlSetState($GOButton, $GUI_DISABLE)
                    ;EndIf
                    ;If $CredCheck <> 0 Then

                Else ; you get here is $CredCheck is anything other than 0 so why use a second If <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ; As we are moving on - we need to clear the message handler for this function
                    GUIRegisterMsg($WM_COMMAND, "")
                    GUIDelete($CNLRA)
                    CheckPermissions()
                    ;Exit ; Why Exit here - just do it from within the Menu01 function as I mentioned above
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>ComputerNamingLizardCreds

Func CheckPermissions()

    ; Declare these a Global at the top of the script - not within a function ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $ComputerNamingLizardLocalRemote = _ismembertoken('Scripts Computer Naming Lizard Local & Remote', GUICtrlRead($Username))
    Local $ComputerNamingLizardLocal = _ismembertoken('Scripts Computer Naming Lizard Local', GUICtrlRead($Username))

    ; Now we create a token so that the renaming function knows which permissions the user has <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $iToken = 0
    If $ComputerNamingLizardLocalRemote = 'True' Then
        $iToken = 2 ; Token = 2 if Remote and Local are True <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf
    If $ComputerNamingLizardLocal = 'True' Then
        $iToken = 1 ; Token = 1 if only Local is True <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf
    ; Now check we have at least one permission <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $iToken <> 0 Then
        ; Call the function with the token <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Menu01($iToken)
    Else
        ; If neither is True we get here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        MsgBox(16, 'Permission Required', 'You do not have appropriate permissions to run this utility')
        Exit ; And here I take it you do want to exit the whole script! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    ; As we never use them again, why even bother to reset them to 0? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ;$ComputerNamingLizardLocalRemote = '0'
    ;$ComputerNamingLizardLocal = '0'

EndFunc   ;==>CheckPermissions

; This handler runs for the inputs in the ComputerNamingLizardCreds function
Func _WM_COMMAND_Creds($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $Username
                If StringLen(GUICtrlRead($Username)) = 5 Then
                    GUICtrlSetState($Password, $GUI_ENABLE)
                Else
                    GUICtrlSetState($Password, $GUI_DISABLE)
                EndIf
            Case $Password
                If StringLen(GUICtrlRead($Password)) = 8 Then
                    GUICtrlSetState($GOButton, $GUI_ENABLE)
                Else
                    GUICtrlSetState($GOButton, $GUI_DISABLE)
                EndIf
        EndSwitch
    EndIf

EndFunc   ;==>_WM_COMMAND_Creds

; This handler runs for the inputs in the Menu01 function
Func _WM_COMMAND_Menu01($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $sData

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $cInput_Room_Inits
                $sData = GUICtrlRead($cInput_Room_Inits)
                If GUICtrlRead($cCombo_Type) = "Non-Instructional" Then
                    ; Need only uppercase alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alpha:]]", ""))
                Else
                    ; Need digits or alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", ""))
                EndIf
                GUICtrlSetData($cInput_Room_Inits, $sData)
                ; And we need 4 of them
                If StringLen($sData) = 4 Then
                    ; Enable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_ENABLE)
                Else
                    ; Disable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                EndIf
            Case $cInput_Comp
                ; Need 2 digits only
                $sData = GUICtrlRead($cInput_Comp)
                $sData = StringRegExpReplace(GUICtrlRead($cInput_Comp), "[^[:digit:]]", "")
                GUICtrlSetData($cInput_Comp, $sData)
                If StringLen($sData) = 2 Then
                    GUICtrlSetState($cButton_Comp, $GUI_ENABLE)
                Else
                    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                EndIf
            Case $cInput_Remote
                ; No idea what you want here
        EndSwitch

    EndIf
EndFunc   ;==>_WM_COMMAND_Menu01

Look for the <<<<<<<<<<<<<<<<<<<<<<<< lines - these explain what I have done and why. I hope it is all self-explanatory, but do not hesitate to ask if anything is unclear. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

thank you again Melba23

I'm testing what you've provided and it seems the GUICtrlRead($Username) isn't passing to the CheckPermissions function. I put a MsgBox in that function with GUICtrlRead($Username) in it and it comes up blank.

I really like the explainations you've provided for me and I can see my logic isn't logical at all, don't worry... I've been accused more than once of 'thinking outside the box'

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

Ooops! I can see why - give me a moment to recode it. :>

M23

Edit:

In tidying up the script I had deleted the GUI before I tried to read the input. :>

This version reads the content before deleting the GUI and passes it to the other function as a parameter - look at lines #547-552 to see the difference: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <ComboConstants.au3>
#include <TokenGroup.au3>
#include <File.au3>

;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

; Declare as Global here, not inside a function
Global $Username, $Password, $GOButton
Global $cButton_Comp, $cButton_Room_Inits, $cProgress_Renaming, $cCombo_Type
Global $cInput_Comp, $cInput_Room_Inits, $cInput_Remote, $cInput_Name_1

; Now not needed
;Global $ComputerNamingLizardLocalRemote, $ComputerNamingLizardLocal

;Checks to see if the file exists and then deletes it
FileDelete('%TEMP%ServersList')

Run('taskkill.exe /IM AISD-411*', '', @SW_HIDE)

;Checks to see if this is running in Windows PE while imaging a computer from a thumb drive
If FileExists('X:WindowsSystem32Sysprep') Then

    ;$ImagingComputer = '1' ; Now not needed

    Menu01(0) ; Pass the required state to the function directly - in this case 0 = "Imaging only" <<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; What do you want to do here? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; At the moment you just continue with the rest of the script which I assume you do not want
    ; Surely you want to exit now as the renaming has been done?
    ; I suggest you exit directly from the Menu01 function and that is what I have coded

Else

    ; Might as well put this here! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ;GUI for user to input username and password to check if they have network access
    ComputerNamingLizardCreds()

EndIf

;Checks to see if the supplied user credentials is a memeber of a specific network security group
;If the user is a memeber of 'Scripts Computer Naming Lizard Local & Remote' then they are able to change a local or remote computer
;If the user is a memeber of 'Scripts Computer Naming Lizard Local' then they are able to ONLY change local computers, REMOTE and LOCAL options never show, just the CHANGE LOCAL NAME NOW button

; There is no point in calling thisfunction here as we never reach this point <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Either we exit from the Creds function if creds cannot be verified or from the Menu01 function when it completes or fails
; CheckPermissions()

; #########################################################################

Func Menu01($iToken)

    Local $sIni = "Data.ini", $vMsg

    ; Read the ini section
    Local $aCampus = IniReadSection($sIni, "Campus")
    ; Convert into a string to fill the combo
    Local $sCampus = ""
    For $i = 1 To $aCampus[0][0]
        $sCampus &= "|" & $aCampus[$i][0]
    Next

    ; And do the same for the other sections
    Local $aEarlies = IniReadSection($sIni, "Earlies")
    Local $sEarlies = ""
    For $i = 1 To $aEarlies[0][0]
        $sEarlies &= "|" & $aEarlies[$i][0]
    Next

    Local $aElementary = IniReadSection($sIni, "Elementary")
    Local $sElementary = ""
    For $i = 1 To $aElementary[0][0]
        $sElementary &= "|" & $aElementary[$i][0]
    Next

    Local $aMiddle = IniReadSection($sIni, "Middle")
    Local $sMiddle = ""
    For $i = 1 To $aMiddle[0][0]
        $sMiddle &= "|" & $aMiddle[$i][0]
    Next

    Local $aHigh = IniReadSection($sIni, "High")
    Local $sHigh = ""
    For $i = 1 To $aHigh[0][0]
        $sHigh &= "|" & $aHigh[$i][0]
    Next

    Local $aNonInstructional = IniReadSection($sIni, "Non-Instructional")
    Local $sNonInstructional = ""
    For $i = 1 To $aNonInstructional[0][0]
        $sNonInstructional &= "|" & $aNonInstructional[$i][0]
    Next

    Local $aDepartment = IniReadSection($sIni, "Department")
    Local $sDepartment = ""
    For $i = 1 To $aDepartment[0][0]
        $sDepartment &= "|" & $aDepartment[$i][0]
    Next

    Local $aRoom = IniReadSection($sIni, "Room")
    Local $sRoom = ""
    For $i = 1 To $aRoom[0][0]
        $sRoom &= "|" & $aRoom[$i][0]
    Next

    Local $aUser = IniReadSection($sIni, "User")
    Local $sUser = ""
    For $i = 1 To $aUser[0][0]
        $sUser &= "|" & $aUser[$i][0]
    Next

    ; Create GUI - all items created and hidden until ready
    GUICreate("Computer Renaming Lizard", 500, 560)

    GUICtrlCreateLabel("Campus Type", 10, 15, 200, 20)
    $cCombo_Type = GUICtrlCreateCombo("", 10, 40, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sCampus)

    Local $cLabel_Location = GUICtrlCreateLabel("Location", 10, 75, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Location = GUICtrlCreateCombo("", 10, 100, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Dept = GUICtrlCreateLabel("", 10, 135, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Room_Dept = GUICtrlCreateCombo("", 10, 160, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Inits = GUICtrlCreateLabel("", 10, 195, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Room_Inits = GUICtrlCreateInput("", 110, 195, 50, 20)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Room_Inits = GUICtrlCreateButton("Accept", 175, 195, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    Local $cLabel_User = GUICtrlCreateLabel("User", 10, 230, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_User = GUICtrlCreateCombo("", 10, 255, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sUser)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Comp = GUICtrlCreateLabel("Computer Number", 10, 290, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Comp = GUICtrlCreateInput("", 110, 290, 50, 20)
    GUICtrlSetLimit(-1, 2)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Comp = GUICtrlCreateButton("Accept", 175, 290, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    GUIStartGroup()
    Local $cRadio_Local = GUICtrlCreateRadio(" Local Computer", 10, 380, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cRadio_Remote = GUICtrlCreateRadio(" Remote Computer", 10, 410, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Remote = GUICtrlCreateInput("", 30, 430, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Remote = GUICtrlCreateButton("Accept", 30, 460, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $sLabel_Checking = GUICtrlCreateLabel("Checking Computer" & @CRLF & "Account Type", 140, 460, 200, 40)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Rename = GUICtrlCreateButton("", 260, 380, 200, 100)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Renaming = GUICtrlCreateLabel("", 10, 500, 480, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cProgress_Renaming = GUICtrlCreateProgress(10, 530, 480, 20, $PBS_MARQUEE)
    GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50)
    GUICtrlSetState(-1, $GUI_HIDE)

    ; These are created last as we never want to hide them
    GUICtrlCreateLabel("Computer Name", 10, 340, 100, 20)
    GUICtrlCreateLabel("-", 150, 340, 10, 20)
    GUICtrlCreateLabel("-", 180, 340, 10, 20)
    GUICtrlCreateLabel("-", 260, 340, 10, 20)
    $cInput_Name_1 = GUICtrlCreateInput("", 110, 340, 40, 20, $ES_READONLY)
    Local $cInput_Name_2 = GUICtrlCreateInput("", 160, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_3 = GUICtrlCreateInput("", 190, 340, 70, 20, $ES_READONLY)
    Local $cInput_Name_4 = GUICtrlCreateInput("", 270, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_5 = GUICtrlCreateInput("", 290, 340, 40, 20, $ES_READONLY)

    ; Create dummy to fire Local rename <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLocal_Dummy = GUICtrlCreateDummy()

    GUISetState()

    #endregion ; Create GUI

    ; Register the input change message to control what happen in the inputs
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Menu01")

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ;GUIDelete($hGUI) ; No need as we exit directly
                 Exit

            Case $cCombo_Type
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Dept, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Location, $GUI_SHOW)
                GUICtrlSetState($cCombo_Location, $GUI_SHOW)
                ; Set the next combo depending on what was selected
                Switch GUICtrlRead($cCombo_Type)
                    Case "Earlies"
                        GUICtrlSetData($cCombo_Location, $sEarlies)
                    Case "Elementary"
                        GUICtrlSetData($cCombo_Location, $sElementary)
                    Case "Middle"
                        GUICtrlSetData($cCombo_Location, $sMiddle)
                    Case "High"
                        GUICtrlSetData($cCombo_Location, $sHigh)
                    Case "Non-Instructional"
                        GUICtrlSetData($cCombo_Location, $sNonInstructional)
                EndSwitch

            Case $cCombo_Location
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Dept, $GUI_SHOW)
                GUICtrlSetState($cCombo_Room_Dept, $GUI_SHOW)
                ; Read the combos
                Local $sLocation = GUICtrlRead($cCombo_Location)
                Local $sType = GUICtrlRead($cCombo_Type)
                ; Fill in the computer name section by reading the ini file by reading the ini file
                GUICtrlSetData($cInput_Name_1, IniRead($sIni, $sType, $sLocation, "###"))
                ; Set the next combo depending on what was selected
                Switch $sType
                    Case "Non-Instructional"
                        GUICtrlSetData($cLabel_Room_Dept, "Department")
                        GUICtrlSetData($cCombo_Room_Dept, $sDepartment)
                    Case Else
                        GUICtrlSetData($cLabel_Room_Dept, "Room Type")
                        GUICtrlSetData($cCombo_Room_Dept, $sRoom)
                EndSwitch

            Case $cCombo_Room_Dept
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 1)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Inits, $GUI_SHOW)
                GUICtrlSetState($cInput_Room_Inits, $GUI_SHOW)
                GUICtrlSetData($cInput_Room_Inits, "")
                GUICtrlSetState($cButton_Room_Inits, $GUI_SHOW)
                ; Read the combo
                Local $sRoom_Dept = GUICtrlRead($cCombo_Room_Dept)
                ; Depending on selection
                Switch $sType
                    Case "Non-Instructional"
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Department", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "User Initials")
                    Case Else
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Room", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "Room Number")
                EndSwitch
                ; Set focus on the input
                GUICtrlSetState($cInput_Room_Inits, $GUI_FOCUS)

            Case $cButton_Room_Inits
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_3, GUICtrlRead($cInput_Room_Inits))
                GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                ; Show the next level down
                GUICtrlSetState($cLabel_User, $GUI_SHOW)
                GUICtrlSetState($cCombo_User, $GUI_SHOW)

            Case $cCombo_User
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Comp, 3)
                ; Show the next level down
                GUICtrlSetState($cLabel_Comp, $GUI_SHOW)
                GUICtrlSetState($cInput_Comp, $GUI_SHOW)
                GUICtrlSetData($cInput_Comp, "")
                GUICtrlSetState($cButton_Comp, $GUI_SHOW)
                ; Read the combo
                $sUser = GUICtrlRead($cCombo_User)
                ; Fill in the computer name section by reading the ini file
                GUICtrlSetData($cInput_Name_4, IniRead($sIni, "User", $sUser, "###"))
                ; Set focus to the input
                GUICtrlSetState($cInput_Comp, $GUI_FOCUS)

            Case $cButton_Comp
                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_5, GUICtrlRead($cInput_Comp))
                GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                ; Read complete name
                Local $LizardComputerName = GUICtrlRead($cInput_Name_1) & "-" & GUICtrlRead($cInput_Name_2) & "-" & GUICtrlRead($cInput_Name_3) & "-" & GUICtrlRead($cInput_Name_4) & GUICtrlRead($cInput_Name_5)
                ; Show the next level down depending on the token passed to the function
                Switch $iToken
                    Case 0
                        ; Imaging token passed
                        GUICtrlSetData($cButton_Rename, "Change Image Name Now!")
                        GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                    Case 1
                        ; Local only rename permission token passed - so act as if that radio was selected
                        ; Set the Local radio to checked and fire the dummy to run the event code ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        GUICtrlSetState($cRadio_Local, $GUI_CHECKED)
                        GUICtrlSendToDummy($cLocal_Dummy)
                    Case 2
                        ; Remote & Local rename permission token passed
                        GUICtrlSetState($cRadio_Local, $GUI_SHOW)
                        GUICtrlSetState($cRadio_Remote, $GUI_SHOW)
                EndSwitch

            Case $cRadio_Local, $cLocal_Dummy
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                GUICtrlSetData($cButton_Rename, "Change Local Name Now!")
                ; Show the Rename button
                GUICtrlSetState($cButton_Rename, $GUI_SHOW)

            Case $cRadio_Remote
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                ; Show the required controls
                GUICtrlSetState($cInput_Remote, BitOR($GUI_SHOW, $GUI_FOCUS))
                GUICtrlSetData($cInput_Remote, "")
                GUICtrlSetState($cButton_Remote, $GUI_SHOW)

            Case $cButton_Remote
                ; Set controls
                GUICtrlSetState($cInput_Remote, $GUI_DISABLE)
                GUICtrlSetState($cButton_Remote, $GUI_DISABLE)
                GUICtrlSetState($sLabel_Checking, $GUI_SHOW)
                GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                ;runs a DSQUERY to get names of servers and not allow the program to continue, we don't want servers renamed, this runs a dsquery from a specified location
                RunWait('cmd /c SpecifiedLocationdsquery.exe * "DC=domainname,DC=org" -limit 0 -filter "(&(OperatingSystem=*server*))" > %TEMP%ServersList', '', @SW_HIDE)
                Do
                    Sleep(1000)
                Until FileExists('%TEMP%ServersList')
                ; Hide label and progress
                GUICtrlSetState($sLabel_Checking, $GUI_HIDE)
                GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                ; $FileOpen = FileOpen('%TEMP%ServersList', 0) ; No need to open it to read it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                ; $sFile_Text = FileRead('%TEMP%ServersList') ; Just read it below <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                Local $String = StringInStr(FileRead('%TEMP%ServersList'), GUICtrlRead($cInput_Remote))
                If $String > 0 Then
                    ;FileClose($FileOpen) ; Now not opened <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    FileDelete('%TEMP%ServersList')
                    MsgBox(16, 'Remote Computer Error!', 'Computer Account Type Does Not Allow Changing Name')
                    ; You said the idea was not to continue if it was a server - so here seems a good point to exit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    Exit
                    ; And so there is no need for these <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ;GUICtrlSetData($NameRemoteComputerInput, '')
                    ;GUICtrlSetState($NameRemoteComputerInput, $GUI_ENABLE)
                    ;GUICtrlSetState($NameRemoteComputerCheckbox, $GUI_UNCHECKED + $GUI_ENABLE)
                    ;GUICtrlSetState($PleaseWait, $GUI_HIDE)
                Else
                    ; $String = 0 so not a server
                    GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                    ; Show the Rename button
                    GUICtrlSetData($cButton_Rename, "Change Remote Name Now!")
                    GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                EndIf

            Case $cButton_Rename
                ; Are we imaging
                If $iToken = 0 Then
                    ;Unable to get this working with sysprep at the moment, it does change the line I want it to change it's just that Sysprep still names the computer whatever it desires! HAHA
                    GUICtrlSetData($cLabel_Renaming, 'Setting Computer Name To: ' & $LizardComputerName)
                    ; Disable all controls
                    For $i = $cCombo_Type To $cButton_Rename
                        GUICtrlSetState($i, $GUI_DISABLE)
                    Next

                    _FileWriteToLine('E:WindowsSystem32sysprepAISDUnattend.Enterprise.x86.xml', 31, '<ComputerName>' & $LizardComputerName & '</ComputerName>', 0)

                    MsgBox(0, "Imaging Complete", "Computer Name set to:" & $LizardComputerName)
                    Exit

                Else ; It is a Local or Remote rename
                    ; Was local selected
                    If GUICtrlRead($cRadio_Local) = 1 Then
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Local Computer Name From: ' & @ComputerName & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomLocalComputer = RunWait('SpecifiedLocationnetdom.exe renamecomputer ' & @ComputerName & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:10', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;Below are possible error codes that netdom will pass, I would like for these to popup a msgbox indicating errors. Error 0 is success
                        Switch $NetdomLocalComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                ; No need to clear anything, we will just exit when the above MsgBox is cleared
                                Exit
                                ;GUICtrlSetState($ProgressBar, $GUI_HIDE)
                                ;GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                                ;GUICtrlSetState($cButton_Rename, $GUI_DISABLE)
                                ;GUICtrlSetState($ExitNamingLizard, $GUI_SHOW)
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomLocalComputer
                                    Case 53
                                        $vMsg = 'Local Computer Not Found'
                                    Case 87
                                        $vMsg = 'Local Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Local Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so re-enable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    Else ; Remote was selected
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Remote Computer Name From: ' & GUICtrlRead($cInput_Remote) & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomRemoteComputer = RunWait('cmd /c SpecifiedLocationnetdom.exe renamecomputer ' & GUICtrlRead($cInput_Remote) & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:05', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;again showing error codes passed from the netdom Executable
                        Switch $NetdomRemoteComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                ; No need to clear anything, we will just exit when the above MsgBox is cleared
                                Exit
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomRemoteComputer
                                    Case 53
                                        $vMsg = 'Remote Computer Not Found'
                                    Case 87
                                        $vMsg = 'Remote Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Remote Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes" and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so reenable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    EndIf
                EndIf
        EndSwitch
    WEnd

EndFunc   ;==>Menu01

Func _Clear_All_Below($cCID, $iIndex = 5)

    ; Force the "Accept" buttons to disabled
    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
    ; Hide all controls after the one passed
    For $i = $cCID To $cProgress_Renaming
        GUICtrlSetState($i, $GUI_HIDE)
    Next
    ; Empty the computer name inputs as required
    For $i = $iIndex To 4
        GUICtrlSetData($cInput_Name_1 + $i, "")
    Next

EndFunc   ;==>_Clear_All_Below

Func ComputerNamingLizardCreds()

    Local $CNLRA = GUICreate("Computer Naming Lizard RunAs", 320, 150) ; Only needs to be in Local scope

    $Username = GUICtrlCreateInput('', 80, 30, 220, 20)
    GUICtrlSetLimit(-1, 5)
    $Password = GUICtrlCreateInput('', 80, 60, 220, 20, $ES_PASSWORD)
    GUICtrlSetLimit(-1, 8)
    GUICtrlSetState($Password, $GUI_DISABLE)
    GUICtrlCreateLabel('Username and Password to RunAs', 5, 10, 200, 20)
    GUICtrlCreateLabel('Username:', 20, 32.5, 50, 20)
    GUICtrlCreateLabel('Password:', 20, 62.5, 50, 20)

    $GOButton = GUICtrlCreateButton('GO!', 110, 90, 100, 40)
    GUICtrlSetState($GOButton, BitOR($GUI_DISABLE, $GUI_DEFBUTTON)) ; Always use BitOR to combine styles <<<<<<<<<<<<<<<<<

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Creds")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                MsgBox(16, 'Error', 'Renaming Aborted')
                Exit ; I take that using the [X] means that you should exit the whole script <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $GOButton
                ;runs as user supplied credentials, ComputerNamingLizardCredentialsCheck.exe just opens and closes notepad.exe
                Local $CredCheck = RunAs(GUICtrlRead($Username), 'domainname', GUICtrlRead($Password), 0, 'networklocationComputerNamingLizardCredentialsCheck.exe', '', @SW_HIDE)

                If $CredCheck = 0 Then
                    MsgBox(48, 'Error', 'Incorrect username and/or password')
                    ;GUICtrlSetState($GOButton, $GUI_ENABLE)
                    ;GUIDelete($CNLRA)
                    ; ComputerNamingLizardCreds()  ; Very bad use of recursion here !!!!!!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ; I would just continue the loop until the correct username/password is entered or dialog is closed via the [X]
                    ; So we need to do this to reset the dialog
                    GUICtrlSetData($Username, "")
                    GUICtrlSetData($Password, "")
                    GUICtrlSetState($Password, $GUI_DISABLE)
                    GUICtrlSetState($GOButton, $GUI_DISABLE)
                    ;EndIf
                    ;If $CredCheck <> 0 Then

                Else ; you get here is $CredCheck is anything other than 0 so why use a second If <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ; As we are moving on - we need to clear the message handler for this function
                    GUIRegisterMsg($WM_COMMAND, "")
                    ; Read the username
                    $sUserName = GUICtrlRead($Username)
                    ; Now delete the GUI
                    GUIDelete($CNLRA)
                    ; And pass the username to the next function
                    CheckPermissions($sUserName)
                    ;Exit ; Why Exit here - just do it from within the Menu01 function as I mentioned above
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>ComputerNamingLizardCreds

Func CheckPermissions($sUserName)

    ; Declare these as Local - we only use them in this function now; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $ComputerNamingLizardLocalRemote = _ismembertoken('Scripts Computer Naming Lizard Local & Remote', $sUserName)
    Local $ComputerNamingLizardLocal = _ismembertoken('Scripts Computer Naming Lizard Local', $sUsername)

    ; Now we create a token so that the renaming function knows which permissions the user has <<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $iToken = 0
    If $ComputerNamingLizardLocalRemote = 'True' Then
        $iToken = 2 ; Token = 2 if Remote and Local are True <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf
    If $ComputerNamingLizardLocal = 'True' Then
        $iToken = 1 ; Token = 1 if only Local is True <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf
    ; Now check we have at least one permission <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $iToken <> 0 Then
        ; Call the function with the token <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Menu01($iToken)
    Else
        ; If neither is True we get here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        MsgBox(16, 'Permission Required', 'You do not have appropriate permissions to run this utility')
        Exit ; And here I take it you do want to exit the whole script! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    ; As we never use them again, why even bother to reset them to 0? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ;$ComputerNamingLizardLocalRemote = '0'
    ;$ComputerNamingLizardLocal = '0'

EndFunc   ;==>CheckPermissions

; This handler runs for the inputs in the ComputerNamingLizardCreds function
Func _WM_COMMAND_Creds($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $Username
                If StringLen(GUICtrlRead($Username)) = 5 Then
                    GUICtrlSetState($Password, $GUI_ENABLE)
                Else
                    GUICtrlSetState($Password, $GUI_DISABLE)
                EndIf
            Case $Password
                If StringLen(GUICtrlRead($Password)) = 8 Then
                    GUICtrlSetState($GOButton, $GUI_ENABLE)
                Else
                    GUICtrlSetState($GOButton, $GUI_DISABLE)
                EndIf
        EndSwitch
    EndIf

EndFunc   ;==>_WM_COMMAND_Creds

; This handler runs for the inputs in the Menu01 function
Func _WM_COMMAND_Menu01($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $sData

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $cInput_Room_Inits
                $sData = GUICtrlRead($cInput_Room_Inits)
                If GUICtrlRead($cCombo_Type) = "Non-Instructional" Then
                    ; Need only uppercase alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alpha:]]", ""))
                Else
                    ; Need digits or alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", ""))
                EndIf
                GUICtrlSetData($cInput_Room_Inits, $sData)
                ; And we need 4 of them
                If StringLen($sData) = 4 Then
                    ; Enable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_ENABLE)
                Else
                    ; Disable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                EndIf
            Case $cInput_Comp
                ; Need 2 digits only
                $sData = GUICtrlRead($cInput_Comp)
                $sData = StringRegExpReplace(GUICtrlRead($cInput_Comp), "[^[:digit:]]", "")
                GUICtrlSetData($cInput_Comp, $sData)
                If StringLen($sData) = 2 Then
                    GUICtrlSetState($cButton_Comp, $GUI_ENABLE)
                Else
                    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                EndIf
            Case $cInput_Remote
                ; No idea what you want here
        EndSwitch

    EndIf
EndFunc   ;==>_WM_COMMAND_Menu01

Let me know if anything else does not work. :)

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

so you're setting $sUserName to read the $Username input to pass it to the next function and the next function reads the $sUserName provided by the user.

I thought that a variable within a function could only be seen by that function and not any other functions. I guess this thought is incorrect?

Thank you again for all your help

I will have to review all the notes you made so I can try to better understand how you have written this and hopefully teach me!

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

I thought that a variable within a function could only be seen by that function and not any other functions. I guess this thought is incorrect?

No, you are correct - a Local variable is only visible within that function. But in this case we are passing the variable as a parameter to the next function - in that case the function creates its own variable with that value. I suggest reading the Variables - using Global, Local and ByRef tutorial in the Wiki to learn more. ;)

And as i said, when you have read all the comments please do ask if anything I have done or ths reasons for my doing it are unclear. :)

M23

P.S. And please add a Local in front of $sUsername in line #548 of that script - I really should have done so myself when coding it. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Elephant007

Amazing, great work..

I am carefully tweaking the script making sure not to make a nightmare of it, I especially like the tip you gave about using BitOr to combine!

I tried getting it so the Accept buttons will use enter to accept the number with GUICtrlSetState(-1, BitOr($GUI_HIDE, $GUI_ENABLE, $GUI_DEFBUTTON))

I added this under both the Accept GUI's Lines #140, #154 and #164. The only one that accepts enter to continue is #154... any hints?

Share this post


Link to post
Share on other sites
Melba23

Elephant007,

As far as I know you can only set one DEFBUTTON as you create the script - you cannot change it "on the fly". What I suggest is setting "ENTER" to act as an Accelerator key and linking it to each button as they are activated. Take a look at the <<<<<< lines in this version of the script: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <ComboConstants.au3>
#include <TokenGroup.au3>
#include <File.au3>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

; Declare as Global here, not inside a function
Global $Username, $Password, $GOButton
Global $cButton_Comp, $cButton_Room_Inits, $cProgress_Renaming, $cCombo_Type
Global $cInput_Comp, $cInput_Room_Inits, $cInput_Remote, $cInput_Name_1

;Checks to see if the file exists and then deletes it
FileDelete('%TEMP%ServersList')

Run('taskkill.exe /IM AISD-411*', '', @SW_HIDE)

;Checks to see if this is running in Windows PE while imaging a computer from a thumb drive
If FileExists('X:WindowsSystem32Sysprep') Then
    Menu01(0)
Else
    ;GUI for user to input username and password to check if they have network access
    ComputerNamingLizardCreds()
EndIf

; #########################################################################

Func Menu01($iToken)

    Local $sIni = "Data.ini", $vMsg

    ; Read the ini section
    Local $aCampus = IniReadSection($sIni, "Campus")
    ; Convert into a string to fill the combo
    Local $sCampus = ""
    For $i = 1 To $aCampus[0][0]
        $sCampus &= "|" & $aCampus[$i][0]
    Next

    ; And do the same for the other sections
    Local $aEarlies = IniReadSection($sIni, "Earlies")
    Local $sEarlies = ""
    For $i = 1 To $aEarlies[0][0]
        $sEarlies &= "|" & $aEarlies[$i][0]
    Next

    Local $aElementary = IniReadSection($sIni, "Elementary")
    Local $sElementary = ""
    For $i = 1 To $aElementary[0][0]
        $sElementary &= "|" & $aElementary[$i][0]
    Next

    Local $aMiddle = IniReadSection($sIni, "Middle")
    Local $sMiddle = ""
    For $i = 1 To $aMiddle[0][0]
        $sMiddle &= "|" & $aMiddle[$i][0]
    Next

    Local $aHigh = IniReadSection($sIni, "High")
    Local $sHigh = ""
    For $i = 1 To $aHigh[0][0]
        $sHigh &= "|" & $aHigh[$i][0]
    Next

    Local $aNonInstructional = IniReadSection($sIni, "Non-Instructional")
    Local $sNonInstructional = ""
    For $i = 1 To $aNonInstructional[0][0]
        $sNonInstructional &= "|" & $aNonInstructional[$i][0]
    Next

    Local $aDepartment = IniReadSection($sIni, "Department")
    Local $sDepartment = ""
    For $i = 1 To $aDepartment[0][0]
        $sDepartment &= "|" & $aDepartment[$i][0]
    Next

    Local $aRoom = IniReadSection($sIni, "Room")
    Local $sRoom = ""
    For $i = 1 To $aRoom[0][0]
        $sRoom &= "|" & $aRoom[$i][0]
    Next

    Local $aUser = IniReadSection($sIni, "User")
    Local $sUser = ""
    For $i = 1 To $aUser[0][0]
        $sUser &= "|" & $aUser[$i][0]
    Next

    ; Create GUI - all items created and hidden until ready
    GUICreate("Computer Renaming Lizard", 500, 560)

    GUICtrlCreateLabel("Campus Type", 10, 15, 200, 20)
    $cCombo_Type = GUICtrlCreateCombo("", 10, 40, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sCampus)

    Local $cLabel_Location = GUICtrlCreateLabel("Location", 10, 75, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Location = GUICtrlCreateCombo("", 10, 100, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Dept = GUICtrlCreateLabel("", 10, 135, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_Room_Dept = GUICtrlCreateCombo("", 10, 160, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Room_Inits = GUICtrlCreateLabel("", 10, 195, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Room_Inits = GUICtrlCreateInput("", 110, 195, 50, 20)
    GUICtrlSetLimit(-1, 4)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Room_Inits = GUICtrlCreateButton("Accept", 175, 195, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    Local $cLabel_User = GUICtrlCreateLabel("User", 10, 230, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cCombo_User = GUICtrlCreateCombo("", 10, 255, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, $sUser)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Comp = GUICtrlCreateLabel("Computer Number", 10, 290, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Comp = GUICtrlCreateInput("", 110, 290, 50, 20)
    GUICtrlSetLimit(-1, 2)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cButton_Comp = GUICtrlCreateButton("Accept", 175, 290, 100, 20)
    GUICtrlSetState(-1, BitOR($GUI_HIDE, $GUI_DISABLE))

    GUIStartGroup()
    Local $cRadio_Local = GUICtrlCreateRadio(" Local Computer", 10, 380, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cRadio_Remote = GUICtrlCreateRadio(" Remote Computer", 10, 410, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cInput_Remote = GUICtrlCreateInput("", 30, 430, 200, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Remote = GUICtrlCreateButton("Accept", 30, 460, 100, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $sLabel_Checking = GUICtrlCreateLabel("Checking Computer" & @CRLF & "Account Type", 140, 460, 200, 40)
    GUICtrlSetState(-1, $GUI_HIDE)
    Local $cButton_Rename = GUICtrlCreateButton("", 260, 380, 200, 100)
    GUICtrlSetState(-1, $GUI_HIDE)

    Local $cLabel_Renaming = GUICtrlCreateLabel("", 10, 500, 480, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
    $cProgress_Renaming = GUICtrlCreateProgress(10, 530, 480, 20, $PBS_MARQUEE)
    GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50)
    GUICtrlSetState(-1, $GUI_HIDE)

    ; These are created last as we never want to hide them
    GUICtrlCreateLabel("Computer Name", 10, 340, 100, 20)
    GUICtrlCreateLabel("-", 150, 340, 10, 20)
    GUICtrlCreateLabel("-", 180, 340, 10, 20)
    GUICtrlCreateLabel("-", 260, 340, 10, 20)
    $cInput_Name_1 = GUICtrlCreateInput("", 110, 340, 40, 20, $ES_READONLY)
    Local $cInput_Name_2 = GUICtrlCreateInput("", 160, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_3 = GUICtrlCreateInput("", 190, 340, 70, 20, $ES_READONLY)
    Local $cInput_Name_4 = GUICtrlCreateInput("", 270, 340, 20, 20, $ES_READONLY)
    Local $cInput_Name_5 = GUICtrlCreateInput("", 290, 340, 40, 20, $ES_READONLY)

    ; Create dummy to fire Local rename
    Local $cLocal_Dummy = GUICtrlCreateDummy()

    GUISetState()

    #endregion ; Create GUI

    ; Register the input change message to control what happen in the inputs
    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Menu01")

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit

            Case $cCombo_Type
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Dept, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Location, $GUI_SHOW)
                GUICtrlSetState($cCombo_Location, $GUI_SHOW)
                ; Set the next combo depending on what was selected
                Switch GUICtrlRead($cCombo_Type)
                    Case "Earlies"
                        GUICtrlSetData($cCombo_Location, $sEarlies)
                    Case "Elementary"
                        GUICtrlSetData($cCombo_Location, $sElementary)
                    Case "Middle"
                        GUICtrlSetData($cCombo_Location, $sMiddle)
                    Case "High"
                        GUICtrlSetData($cCombo_Location, $sHigh)
                    Case "Non-Instructional"
                        GUICtrlSetData($cCombo_Location, $sNonInstructional)
                EndSwitch

            Case $cCombo_Location
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 0)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Dept, $GUI_SHOW)
                GUICtrlSetState($cCombo_Room_Dept, $GUI_SHOW)
                ; Read the combos
                Local $sLocation = GUICtrlRead($cCombo_Location)
                Local $sType = GUICtrlRead($cCombo_Type)
                ; Fill in the computer name section by reading the ini file by reading the ini file
                GUICtrlSetData($cInput_Name_1, IniRead($sIni, $sType, $sLocation, "###"))
                ; Set the next combo depending on what was selected
                Switch $sType
                    Case "Non-Instructional"
                        GUICtrlSetData($cLabel_Room_Dept, "Department")
                        GUICtrlSetData($cCombo_Room_Dept, $sDepartment)
                    Case Else
                        GUICtrlSetData($cLabel_Room_Dept, "Room Type")
                        GUICtrlSetData($cCombo_Room_Dept, $sRoom)
                EndSwitch

            Case $cCombo_Room_Dept
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Room_Inits, 1)
                ; Show the next level down
                GUICtrlSetState($cLabel_Room_Inits, $GUI_SHOW)
                GUICtrlSetState($cInput_Room_Inits, $GUI_SHOW)
                GUICtrlSetData($cInput_Room_Inits, "")

                GUICtrlSetState($cButton_Room_Inits, $GUI_SHOW)
                ; Set the button to fire on "ENTER"
                Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Room_Inits]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                GUISetAccelerators($aAccelKeys)

                ; Read the combo
                Local $sRoom_Dept = GUICtrlRead($cCombo_Room_Dept)
                ; Depending on selection
                Switch $sType
                    Case "Non-Instructional"
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Department", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "User Initials")
                    Case Else
                        ; Fill in the computer name section by reading the ini file
                        GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Room", $sRoom_Dept, "###"))
                        GUICtrlSetData($cLabel_Room_Inits, "Room Number")
                EndSwitch
                ; Set focus on the input
                GUICtrlSetState($cInput_Room_Inits, $GUI_FOCUS)

            Case $cButton_Room_Inits
                ; Prevent the button from firing on "ENTER"
                GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_3, GUICtrlRead($cInput_Room_Inits))
                GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                ; Show the next level down
                GUICtrlSetState($cLabel_User, $GUI_SHOW)
                GUICtrlSetState($cCombo_User, $GUI_SHOW)

            Case $cCombo_User
                ; Hide all lower level controls
                _Clear_All_Below($cLabel_Comp, 3)
                ; Show the next level down
                GUICtrlSetState($cLabel_Comp, $GUI_SHOW)
                GUICtrlSetState($cInput_Comp, $GUI_SHOW)
                GUICtrlSetData($cInput_Comp, "")

                GUICtrlSetState($cButton_Comp, $GUI_SHOW)
                ; Set the button to fire on "ENTER"
                Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Comp]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                GUISetAccelerators($aAccelKeys)

                ; Read the combo
                $sUser = GUICtrlRead($cCombo_User)
                ; Fill in the computer name section by reading the ini file
                GUICtrlSetData($cInput_Name_4, IniRead($sIni, "User", $sUser, "###"))
                ; Set focus to the input
                GUICtrlSetState($cInput_Comp, $GUI_FOCUS)

            Case $cButton_Comp
                ; Prevent the button from firing on "ENTER"
                GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ; Fill in the computer name section by reading the input
                GUICtrlSetData($cInput_Name_5, GUICtrlRead($cInput_Comp))
                GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                ; Read complete name
                Local $LizardComputerName = GUICtrlRead($cInput_Name_1) & "-" & GUICtrlRead($cInput_Name_2) & "-" & GUICtrlRead($cInput_Name_3) & "-" & GUICtrlRead($cInput_Name_4) & GUICtrlRead($cInput_Name_5)
                ; Show the next level down depending on the token passed to the function
                Switch $iToken
                    Case 0
                        ; Imaging token passed
                        GUICtrlSetData($cButton_Rename, "Change Image Name Now!")

                        GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                        ; Set the button to fire on "ENTER"
                        Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Rename]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        GUISetAccelerators($aAccelKeys)

                    Case 1
                        ; Local only rename permission token passed - so act as if that radio was selected
                        GUICtrlSetState($cRadio_Local, $GUI_CHECKED)
                        GUICtrlSendToDummy($cLocal_Dummy)
                    Case 2
                        ; Remote & Local rename permission token passed
                        GUICtrlSetState($cRadio_Local, $GUI_SHOW)
                        GUICtrlSetState($cRadio_Remote, $GUI_SHOW)
                EndSwitch

            Case $cRadio_Local, $cLocal_Dummy
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                GUICtrlSetData($cButton_Rename, "Change Local Name Now!")
                ; Show the Rename button
                GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                ; Set the button to fire on "ENTER"
                Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Rename]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                GUISetAccelerators($aAccelKeys)

            Case $cRadio_Remote
                ; Hide other Rename controls
                _Clear_All_Below($cInput_Remote)
                ; Show the required controls
                GUICtrlSetState($cInput_Remote, BitOR($GUI_SHOW, $GUI_FOCUS))
                GUICtrlSetData($cInput_Remote, "")

                GUICtrlSetState($cButton_Remote, $GUI_SHOW)
                ; Set the button to fire on "ENTER"
                Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Remote]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                GUISetAccelerators($aAccelKeys)

            Case $cButton_Remote
                ; Prevent the button from firing on "ENTER"
                GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ; Set controls
                GUICtrlSetState($cInput_Remote, $GUI_DISABLE)
                GUICtrlSetState($cButton_Remote, $GUI_DISABLE)
                GUICtrlSetState($sLabel_Checking, $GUI_SHOW)
                GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)

                ;runs a DSQUERY to get names of servers and not allow the program to continue, we don't want servers renamed, this runs a dsquery from a specified location
                RunWait('cmd /c SpecifiedLocationdsquery.exe * "DC=domainname,DC=org" -limit 0 -filter "(&(OperatingSystem=*server*))" > %TEMP%ServersList', '', @SW_HIDE)
                Do
                    Sleep(1000)
                Until FileExists('%TEMP%ServersList')

                ; Hide label and progress
                GUICtrlSetState($sLabel_Checking, $GUI_HIDE)
                GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)

                Local $String = StringInStr(FileRead('%TEMP%ServersList'), GUICtrlRead($cInput_Remote))
                If $String > 0 Then
                    FileDelete('%TEMP%ServersList')
                    MsgBox(16, 'Remote Computer Error!', 'Computer Account Type Does Not Allow Changing Name')
                    Exit
                Else
                    ; $String = 0 so not a server
                    GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                    ; Show the Rename button
                    GUICtrlSetData($cButton_Rename, "Change Remote Name Now!")

                    GUICtrlSetState($cButton_Rename, $GUI_SHOW)
                    ; Set the button to fire on "ENTER"
                    Local $aAccelKeys[1][2] = [["{ENTER}", $cButton_Rename]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    GUISetAccelerators($aAccelKeys)

                EndIf

            Case $cButton_Rename
                ; Prevent the button from firing on "ENTER"
                GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ; Are we imaging
                If $iToken = 0 Then
                    ;Unable to get this working with sysprep at the moment, it does change the line I want it to change it's just that Sysprep still names the computer whatever it desires! HAHA
                    GUICtrlSetData($cLabel_Renaming, 'Setting Computer Name To: ' & $LizardComputerName)
                    ; Disable all controls
                    For $i = $cCombo_Type To $cButton_Rename
                        GUICtrlSetState($i, $GUI_DISABLE)
                    Next

                    _FileWriteToLine('E:WindowsSystem32sysprepAISDUnattend.Enterprise.x86.xml', 31, '<ComputerName>' & $LizardComputerName & '</ComputerName>', 0)

                    MsgBox(0, "Imaging Complete", "Computer Name set to:" & $LizardComputerName)
                    Exit

                Else ; It is a Local or Remote rename
                    ; Was local selected
                    If GUICtrlRead($cRadio_Local) = 1 Then
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Local Computer Name From: ' & @ComputerName & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomLocalComputer = RunWait('SpecifiedLocationnetdom.exe renamecomputer ' & @ComputerName & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:10', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;Below are possible error codes that netdom will pass, I would like for these to popup a msgbox indicating errors. Error 0 is success
                        Switch $NetdomLocalComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                Exit
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomLocalComputer
                                    Case 53
                                        $vMsg = 'Local Computer Not Found'
                                    Case 87
                                        $vMsg = 'Local Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Local Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so re-enable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    Else ; Remote was selected
                        ; Show correct label + progress
                        GUICtrlSetData($cLabel_Renaming, 'Changing Remote Computer Name From: ' & GUICtrlRead($cInput_Remote) & ' To: ' & $LizardComputerName)
                        GUICtrlSetState($cLabel_Renaming, $GUI_SHOW)
                        GUICtrlSetState($cProgress_Renaming, $GUI_SHOW)
                        ; Disable all controls
                        For $i = $cCombo_Type To $cButton_Rename
                            GUICtrlSetState($i, $GUI_DISABLE)
                        Next

                        ; Do the renaming
                        Local $NetdomRemoteComputer = RunWait('cmd /c SpecifiedLocationnetdom.exe renamecomputer ' & GUICtrlRead($cInput_Remote) & ' /NewName:' & $LizardComputerName & ' /UserD:domainnamenamer /PasswordD:password /Force /REBoot:05', '', @SW_HIDE)

                        ; Hide label and progress
                        GUICtrlSetState($cLabel_Renaming, $GUI_HIDE)
                        GUICtrlSetState($cProgress_Renaming, $GUI_HIDE)
                        ;again showing error codes passed from the netdom Executable
                        Switch $NetdomRemoteComputer
                            Case 0
                                MsgBox(64, 'Computer Naming Lizard', 'Name Change Completed Successfully' & @CRLF & @CRLF & 'Reboot Command Sent To Remote Computer')
                                ; No need to clear anything, we will just exit when the above MsgBox is cleared
                                Exit
                            Case Else
                                ; There was a problem so announce it
                                $vMsg = ""
                                Switch $NetdomRemoteComputer
                                    Case 53
                                        $vMsg = 'Remote Computer Not Found'
                                    Case 87
                                        $vMsg = 'Remote Computer Name Already Exists'
                                    Case 2227
                                        $vMsg = 'Account Already Exists'
                                    Case 2697
                                        $vMsg = 'Remote Computer Could Not Be Contacted'
                                EndSwitch
                                ; Create a MsgBox with "Yes" and "No" buttons
                                $vMsg = MsgBox(48 + 4, 'Computer Naming Lizard', $vMsg & @CRLF & @CRLF & 'No Changes Made' & @CRLF & @CRLF & 'Do You Want To Try Again?')
                                If $vMsg = 7 Then
                                    ; No was pressed
                                    Exit
                                Else
                                    ; Yes was pressed, so reenable the button
                                    GUICtrlSetState($cButton_Rename, $GUI_ENABLE)
                                EndIf
                        EndSwitch
                    EndIf
                EndIf
        EndSwitch
    WEnd

EndFunc   ;==>Menu01

Func _Clear_All_Below($cCID, $iIndex = 5)

    ; Force the "Accept" buttons to disabled
    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)

    ; Prevent any button from firing on "ENTER"
    GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Hide all controls after the one passed
    For $i = $cCID To $cProgress_Renaming
        GUICtrlSetState($i, $GUI_HIDE)
    Next
    ; Empty the computer name inputs as required
    For $i = $iIndex To 4
        GUICtrlSetData($cInput_Name_1 + $i, "")
    Next

EndFunc   ;==>_Clear_All_Below

Func ComputerNamingLizardCreds()

    Local $CNLRA = GUICreate("Computer Naming Lizard RunAs", 320, 150)

    $Username = GUICtrlCreateInput('', 80, 30, 220, 20)
    GUICtrlSetLimit(-1, 5)
    $Password = GUICtrlCreateInput('', 80, 60, 220, 20, $ES_PASSWORD)
    GUICtrlSetLimit(-1, 8)
    GUICtrlSetState($Password, $GUI_DISABLE)
    GUICtrlCreateLabel('Username and Password to RunAs', 5, 10, 200, 20)
    GUICtrlCreateLabel('Username:', 20, 32.5, 50, 20)
    GUICtrlCreateLabel('Password:', 20, 62.5, 50, 20)

    $GOButton = GUICtrlCreateButton('GO!', 110, 90, 100, 40)
    GUICtrlSetState($GOButton, $GUI_DISABLE) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_Creds")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                MsgBox(16, 'Error', 'Renaming Aborted')
                Exit ; I take that using the [X] means that you should exit the whole script <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $GOButton
                ; Prevent the button from firing on "ENTER"
                GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ;runs as user supplied credentials, ComputerNamingLizardCredentialsCheck.exe just opens and closes notepad.exe
                Local $CredCheck = RunAs(GUICtrlRead($Username), 'domainname', GUICtrlRead($Password), 0, 'networklocationComputerNamingLizardCredentialsCheck.exe', '', @SW_HIDE)

                If $CredCheck = 0 Then
                    MsgBox(48, 'Error', 'Incorrect username and/or password')
                    GUICtrlSetData($Username, "")
                    GUICtrlSetData($Password, "")
                    GUICtrlSetState($Password, $GUI_DISABLE)
                    GUICtrlSetState($GOButton, $GUI_DISABLE)

                Else ; you get here is $CredCheck is anything other than 0 so why use a second If <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ; As we are moving on - we need to clear the message handler for this function
                    GUIRegisterMsg($WM_COMMAND, "")
                    ; Read the username
                    Local $sUserName = GUICtrlRead($Username)
                    ; Now delete the GUI
                    GUIDelete($CNLRA)
                    ; And pass the username to the next function
                    CheckPermissions($sUserName)
                EndIf
        EndSwitch

    WEnd

EndFunc   ;==>ComputerNamingLizardCreds

Func CheckPermissions($sUserName)

    Local $ComputerNamingLizardLocalRemote = _ismembertoken('Scripts Computer Naming Lizard Local & Remote', $sUserName)
    Local $ComputerNamingLizardLocal = _ismembertoken('Scripts Computer Naming Lizard Local', $sUsername)

    ; Now we create a token so that the renaming function knows which permissions the user has
    Local $iToken = 0
    If $ComputerNamingLizardLocalRemote = 'True' Then
        $iToken = 2 ; Token = 2 if Remote and Local are True
    EndIf
    If $ComputerNamingLizardLocal = 'True' Then
        $iToken = 1 ; Token = 1 if only Local is True
    EndIf
    ; Now check we have at least one permission
    If $iToken <> 0 Then
        ; Call the function with the token
        Menu01($iToken)
    Else
        ; If neither is True we get here
        MsgBox(16, 'Permission Required', 'You do not have appropriate permissions to run this utility')
        Exit
    EndIf

EndFunc   ;==>CheckPermissions

; This handler runs for the inputs in the ComputerNamingLizardCreds function
Func _WM_COMMAND_Creds($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $Username
                If StringLen(GUICtrlRead($Username)) = 5 Then
                    GUICtrlSetState($Password, $GUI_ENABLE)
                Else
                    GUICtrlSetState($Password, $GUI_DISABLE)
                EndIf
            Case $Password
                If StringLen(GUICtrlRead($Password)) = 8 Then
                    GUICtrlSetState($GOButton, $GUI_ENABLE)
                    ; Set the button to fire on "ENTER"
                    Local $aAccelKeys[1][2] = [["{ENTER}", $GOButton]] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    GUISetAccelerators($aAccelKeys)
                Else
                    GUICtrlSetState($GOButton, $GUI_DISABLE)
                    ; Prevent the button from firing on "ENTER"
                    GUISetAccelerators(0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                EndIf
        EndSwitch
    EndIf

EndFunc   ;==>_WM_COMMAND_Creds

; This handler runs for the inputs in the Menu01 function
Func _WM_COMMAND_Menu01($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $sData

    ; Has the input changed
    If $nNotifyCode = $EN_CHANGE Then
        Switch $nID
            Case $cInput_Room_Inits
                $sData = GUICtrlRead($cInput_Room_Inits)
                If GUICtrlRead($cCombo_Type) = "Non-Instructional" Then
                    ; Need only uppercase alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alpha:]]", ""))
                Else
                    ; Need digits or alpha
                    $sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", ""))
                EndIf
                GUICtrlSetData($cInput_Room_Inits, $sData)
                ; And we need 4 of them
                If StringLen($sData) = 4 Then
                    ; Enable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_ENABLE)
                Else
                    ; Disable button
                    GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE)
                EndIf
            Case $cInput_Comp
                ; Need 2 digits only
                $sData = GUICtrlRead($cInput_Comp)
                $sData = StringRegExpReplace(GUICtrlRead($cInput_Comp), "[^[:digit:]]", "")
                GUICtrlSetData($cInput_Comp, $sData)
                If StringLen($sData) = 2 Then
                    GUICtrlSetState($cButton_Comp, $GUI_ENABLE)
                Else
                    GUICtrlSetState($cButton_Comp, $GUI_DISABLE)
                EndIf
            Case $cInput_Remote
                ; No idea what you want here
        EndSwitch

    EndIf
EndFunc   ;==>_WM_COMMAND_Menu01

Accelerator keys are like HotKeys - except that they only fire when your GUI is active. I use them a lot - they have to be linked to a control, but it is easy to create a dummy if necessary. And unlike HotKeys they not not upset other apps running at the same time. :thumbsup:

Any more questions? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×