I was on a Project where I needed to install Virtual Null Modems, since these weren’t physical devices PnP detection wouldn’t work…
I ended up writing this AutoIT Script to use the Add Hardware Wizard.
You are welcome to modify this script to suit your needs to install / configure Hardware. I’m really starting to like AutoIT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ; ; AutoIt3 Source File -- Created with SAPIEN Technologies PrimalScript 2014 ; ; NAME: InstallNullModem.au3 ; ; AUTHOR: Chisholm, Chris - Blue World Enterprises Inc. ; DATE : 11/20/2014 ; ; COMMENT: Installs the Null Modem Hardware using Add Hardware Wizard ; ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = #include <MsgBoxConstants.au3> #include <GuiButton.au3> #include <GuiEdit.au3> #include <GuiListBox.au3> #include <GuiListView.au3> Global $WindowTitle Global $WindowText Global $hListView Global $hButton Global $hEdit Global $hListBox ;This script is used to install the Generic Null Modems Global $arrCOMPorts[2] = ["COM7", "COM8"] ;Define the ComPorts to install Null Modems on AddNullModems($arrCOMPorts) Exit Func AddNullModems($COMPorts) Local $intIndex Run("Hdwwiz.exe") $WindowTitle = "[TITLE:Add Hardware]" $WindowText = "Welcome to the Add Hardware Wizard" WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button2") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "Install the hardware that I &manually select from a list (Advanced)" WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button2") ;Get Control Handle for Install Hardware Manually Radio Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button4") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "If you do not see the hardware category you want, click Show All Devices." WinWait($WindowTitle,$WindowText) $hListView = ControlGetHandle($WindowTitle, $WindowText, "SysListView321") ;Get Control Handle for List View $hControl = _GUICtrlListView_FindText($hListView,"Modems") ;Get Index for Modems Item in List View _GUICtrlListView_SetItemSelected($hListView, $hControl) ;Set List View to Modems Item $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button4") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "Windows will now try to detect your modem." WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button1") ;Get Control Handle for "Don't Detect my Modem CheckBox ControlClick($WindowTitle, $WindowText, $hButton) ;Click the CheckBox $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button5") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "Select the manufacturer and model of your modem." WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button3") ;Get Control Handle for Have Disk Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button WinWait("[TITLE:Install From Disk]","Insert the manufacturer's installation disk") $hEdit = ControlGetHandle("[TITLE:Install From Disk]", "Insert the manufacturer's installation disk", "Edit1") ;Get Control Handle for Path Edit Box _GUICtrlEdit_SetSel($hEdit, 0, -1 ) ;Select all the Text in the Control _GUICtrlEdit_ReplaceSel($hEdit, @ScriptDir) $hButton = ControlGetHandle("[TITLE:Install From Disk]", "Insert the manufacturer's installation disk", "Button1") ;Get Control Handle for OK Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "Select the manufacturer and model of your modem." WinWait($WindowTitle,$WindowText) $hListView = ControlGetHandle($WindowTitle, $WindowText, "SysListView322") ;Get Control Handle for List View $hControl = _GUICtrlListView_FindText($hListView,"Generic NULL Modem (Mark Crossley v2)") ;Get Index for Null Modem Item in List View _GUICtrlListView_SetItemSelected($hListView, $hControl) ;Set List View to Null Modem $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button8") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "On which ports do you want to install it?" WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button2") ;Get Control Handle for Selected Ports Selection ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $hListBox = ControlGetHandle($WindowTitle, $WindowText, "ListBox1") ;Get Control Handle for ListBox For $intIndex = 0 to UBound ($COMPorts) - 1 Local $intPortIndex = _GUICtrlListBox_FindInText($hListBox, $COMPorts[$intIndex]) ;Find ComPort in List If $intPortIndex <> -1 Then _GUICtrlListBox_SetSel ($hListBox, $intPortIndex) EndIf Next $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button10") ;Get Control Handle for Next Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button $WindowText = "Your modem has been set up successfully." WinWait($WindowTitle,$WindowText) $hButton = ControlGetHandle($WindowTitle, $WindowText, "Button11") ;Get Control Handle for Finish Button ControlClick($WindowTitle, $WindowText, $hButton) ;Click the Button EndFunc |
Leave a Reply