; Computer LWS Decommission Script #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Global $EnterPCNames, $ReadExcelNames, $ManuallyChecked, $ExcelReadChecked Opt("TrayAutoPause", 0) Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL, $MB_TOPMOST), "SLHS Computer Removal", "This is the SLHS Computer Removal script Hit Yes to Continue. Hit No if you do not wish to run this script.") MsgBox(BitOR($MB_OK, $MB_SYSTEMMODAL, $MB_TOPMOST), "Make sure Text is set to LWS main Menu.", "Hit Ok once Text is set to LWS and its left on the main Menu.") ; Initial GUI Setup Global $aTaskbarinit = WinGetPos("[CLASS:Shell_TrayWnd]", "") $Window = GUICreate("Choose the method of entering the PC names:", 440, 100, @DesktopWidth, @DesktopHeight) WinSetOnTop("Choose the method of entering the PC names:", "", 1) Global $aWinInitGui = WinGetPos($Window) $EnterPCNames = GUICtrlCreateRadio("Enter PC Names in Manually.", 8, 8, 160, 17) GUICtrlSetState(-1, $GUI_CHECKED) $ReadExcelNames = GUICtrlCreateRadio("Read all names from an Excel File.", 8, 32, 180, 17) Global $GUIContinueButton = GUICtrlCreateButton("Continue", 8, 65, 75, 25, $WS_GROUP) ; Move the Initial GUI to the bottom right WinMove($Window, "", @DesktopWidth - $aWinInitGui[2] - 4, @DesktopHeight - $aWinInitGui[3] - $aTaskbarinit[3] - 4) GUISetState(@SW_SHOW) Sleep(2000) ;---------------------------------------------------------------------------------------------------------------------------- ;-------------------Is checked for each box0------------ $ManuallyChecked = GUICtrlRead($EnterPCNames) $ExcelReadChecked = GUICtrlRead($ReadExcelNames) ; Find out which ones were checked and pull out the name of the Printer. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUIContinueButton If GUICtrlRead($EnterPCNames) = 1 Then ManualEntryFunc() Sleep(2000) else ExcelEntriesFunc() Sleep(2000) EndIf EndSwitch WEnd GUISetState(@SW_ENABLE) GUIDelete($Window) Func ManualEntryFunc() Local $PCname, $PCNameLabel, $PCNameInput, $PCNameView, $GUIContinueButton, $iAnswer, $RNDM, $AVNumber ; Remove the initial Window. GUISetState(@SW_ENABLE) GUIDelete($Window) ;Create the Window to enter the single computer name------------------------------------------------ ; Initial GUI Setup Global $aTaskbarinit = WinGetPos("[CLASS:Shell_TrayWnd]", "") $SinglePCGUI = GUICreate("PC Name to Decommission LWS", 440, 100, @DesktopWidth, @DesktopHeight) WinSetOnTop("Please enter the Computer name to Decommission:", "", 1) Global $aWinInitGui = WinGetPos($SinglePCGUI) ;$EnterPCNames = GUICtrlCreateCheckbox("Enter PC Names in Manually.", 8, 8, 160,17) Local $PCNameLabel = GUICtrlCreateLabel("Enter PC name being removed: ", 8, 15, 165, 20) Local $PCNameInput = GUICtrlCreateInput("", 175, 15, 100, 20) ; 80,20 Local $GUIContinueButton = GUICtrlCreateButton("Continue", 8, 65, 75, 25, $WS_GROUP) ; Move the Initial GUI to the bottom right WinMove($SinglePCGUI, "", @DesktopWidth - $aWinInitGui[2] - 4, @DesktopHeight - $aWinInitGui[3] - $aTaskbarinit[3] - 4) GUISetState(@SW_SHOW) Sleep(2000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUIContinueButton If GUICtrlRead($PCNameInput) = "" Then Local $PCNameLabel = GUICtrlCreateLabel("No computer name entered. ", 8, 35, 165, 20) Sleep(5000) ManualEntryFunc() Else $PCNameView = GUICtrlRead($PCNameInput) WinActivate("You are connected to Epic ""PROD"" Environment", "") ; Activate the Chronicles window Sleep(2000) WinSetState("You are connected to Epic ""PROD"" Environment", "", @SW_ENABLE) Send("{ENTER}" & "{ENTER}" & "11" & "{ENTER}" & "LWS" & "{ENTER}" & "1") Sleep(2000) Send("{ENTER}" & "1" & "{ENTER}" & "1" & "{ENTER}") ; Should be at the Workstation LWS prompt at this time. Now Remove all Entries. ;------------------------------------------------------------------------------------------------------------------------------------- Sleep(2000) Send($PCNameView & "{ENTER}") ;------------Find out if the computer name has an LWS or not and remove it if it does. Local $iAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL, $MB_TOPMOST), "LWS Exists?", "Does this computer have an lws. (Yes/No)") If $iAnswer = 7 Then ; No Answer MsgBox($MB_SYSTEMMODAL, "PC Decommission", "There is no LWS for this PC name.") Sleep(5000) Exit Else ;Yes Answer Send("{home down}" & "{F9}" & sleep(1000) & "{home up}" & "i") Send("{ENTER}" & "52216" & "{ENTER}" & "100000" & "{ENTER}") ;Set 100000-SLHS COMBINATION FDI sleep(2000) Send("{PGUP 7}" & "{ENTER}" & "{F1}") ;Set Exam room workstation: sleep(2000) Send("{PGUP 2}" & "{F1}" & "{ENTER 2}" & "{F1 20}") ;Set Default OTG to Empty and same with additional departments sleep(2000) Send("{PGUP 5}" & "{F1 5}" & "{ENTER 2}" & "{F1 60}") ; Remove all print groups and classifications. Sleep(4000) Send("{PGUP 10}" & "{F1}" & "{ENTER}" & "{DOWN 2}" & "{TAB}" & "No") ; Remove setting for epic hyperspace timeout sleep(4000) Send("{PGUP}" & "{F1}" & "{ENTER}" & "{F1}" & "{ENTER}") ;Remove Department and Profile Department sleep(2000) send("{PGUP}" & "{DOWN 3}" & "{F1}" & "Inactive" & "{ENTER}") send("{F1}" & "{Down}" & "{F1}") ; Generate random number between 1000 and 80000 then ad the AV to front and ask user if there was an error and if so then regenerate and retry. ; This area will create a random number, See if that AV###### has an lws and then verify if it exists. If it does exist ;then it will create another one and look again. Local $AVTaken = "yes" While $AVTaken == "yes" $RNDM = Random(1000, 800000, 1) ; Return an integer between 5 and 20 to determine the length of the string. Local $AVNumber = ("AV" & $RNDM) Send("{UP 3}" & "{F1}" & $AVNumber & "{ENTER}") Sleep(2000) Local $AVAnswer = MsgBox(BitOR($MB_YESNO, $MB_SYSTEMMODAL, $MB_TOPMOST), "LWS Exists for AV###?", "Is there an lws already for this AV###? (Yes/No)") if $AVAnswer == "7" Then sleep(2000) Send("{UP 4}" & "{F1}" & $AVNumber & "{ENTER}") $AVTaken = "no" Sleep(2000) Exit EndIf sleep(2000) WEnd EndIf EndIf EndSwitch WEnd EndFunc ;==>ManualEntryFunc ;----------------Multiple PC name sheet entries----------------------- Func ExcelEntriesFunc() Global $oExcel = _Excel_Open() ;Create an Excel Object Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookNew($oExcel, 1) Local $oExcel = ObjGet("", "Excel.Application") ; Get an existing Excel Object If @error Then MsgBox(0, "ExcelTest", "Error Getting an active Excel Object. Error code: " & Hex(@error, 8)) Exit EndIf For $oWorkbook in $oExcel.Workbooks ;MsgBox(0,"",$oWorkbook.Name) ; this shows a messagebox real quick with the name of the excel sheet its looking at. Not needed in long run. Just for testing. Next WinActivate($oWorkbook.Name) ; Activate the Excel window WinSetState($oWorkbook.Name, "", @SW_SHOW) MsgBox($MB_SYSTEMMODAL, "Enter all PC's to Decommission", "Please Enter all PC's to decommission in the Excel file first column going down. Then Hit OK.") ;----------------Next add all those entered into an array. ; build gui with a listview in it $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $iRows = UBound($aResult, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10. Local $iDimension = UBound($aResult, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional. Local $iCols = UBound($aResult, $UBOUND_COLUMNS) ; Total number of columns. Local $aMax = ubound($aResult) MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _ $iRows & " row(s) & " & $iCols & " column(s). Total Numbers of Elements in Array :" & $aMax) ; This shows the array is being read and is a single dimensional array. Looks like its working ; Create the GUI GUICreate("Decomm PC List", 400, 500) ; Shows overall length and width of GUI $idListview = GUICtrlCreateListView("", 2, 2, 394, 495) ; 2, 2, 394, 268 ; shows lit GUI area that shows the listview. Last 2 numbers are length and width. GUISetState(@SW_SHOW) ; Add columns _GUICtrlListView_AddColumn($idListview, "Computer Names",120) _GUICtrlListView_SetItemCount($idListview, $aMax) ; shows the list length. Might need to tailor to the $aMax ; Now load all the array info into the listview from the excel rangeread. For $iIncrement = 0 to $aMax $aResult[$iIncrement][0] = "PC:" & $iIncrement ; This is not working. Getting a incorrect subscript or subscript dimension range exceeded. Next _GUICtrlListView_AddArray($idListview, $aResult) ;Loop until the user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ; Run the GUI until the dialog is closed sleep(5000) Exit EndFunc ;==>ExcelEntriesFunc