Jump to content

AutoScroll and return values


grimmlock
 Share

Recommended Posts

My apologizes I am really trying to understand. When I copy and paste this I get an error on line 61.

Global $aPCData[$aFileContents[0] + 1][3]

And where would I would put the lists of files?

$list1 = FileRead("C:test.txt") ; <<<<<< file contains list of PCs listed above

$list2 = FileRead("c:test2.txt") ; <<<<<<<< file contains just test123

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

You no doubt get the error because you do not read the file correctly and so have no $aFileContents array to use as a template. I do not normally add a lot of errorchecking into the examples I post - I leave that as "an exercise for the student", as my old maths master used to say. :D

You say you have 18 files - save them all in the same folder as the script and name them as you wish, but with a ".txt" extension. Then add the names of these files (without the extension) to this line:

GUICtrlSetData(-1, "List_1|List_2|List_3") ; Make this the list of files <<<<<<<<<<<<<<<

In this way you will have the list of the filenames in the combo. Later on we can use _FileListToArray to do this for us, but let us deal with one thing at a time. ;)

Now when you select a filename in the combo, the function I gave you will read the appropriate file and:

- 1. Fill the $aPCData array with the data from the file

- 2. Fill the list with the names of the PCs.

When the buttons are pressed you will need to use the _ArraySearch code I gave you yesterday to find out which machine was selected in the list and the associated data in the $aPCData array to use in the other functions (using the index).

Any clearer? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Ok so I took the code from yesterday and added it along with the Global:$aservers.

What is missing?

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>

; Declare a Global array to hold the data for the currently selected list
Global $aPCData
Global $aServers[2][2] = [["PC 1", "test.test1.test1"], ["PC 2", "test1.test1.test1"]]

GUICreate("test", 400, 400)
GUISetState(@SW_SHOW)

Local $cCombo = GUICtrlCreateCombo("", 10, 10, 100, 20)
GUICtrlSetData(-1, "Test|List_2|List_3") ; So you have all the lists able to be selected from the combo
Local $cList = GUICtrlCreateList("", 10, 50, 100, 50)
Local $cButton_1 = GUICtrlCreateButton("Notepad", 200, 50, 100, 100)
Local $cButton_2 = GUICtrlCreateButton("Wake On Lan", 200, 200, 100, 100)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cCombo
            ; Read the selection
            $sSelection = GUICtrlRead($cCombo)
            ; Open the file and get back a a list
            $sList = _ReadFile($sSelection)
            ; Fill the List with that data
            GUICtrlSetData($cList, $sList)

        Case $cbutton_1
            Local $Input3 = GUICtrlRead($clist)
            ; Find the PC in the array
            $iIndex = _ArraySearch($aServers, $Input3)
            ; Did we find a match?
            If $iIndex <> -1 Then
                ; Get the associated IP and trim as required
                Local $Input4 = StringTrimRight($aServers[$iIndex][1], 12)
                Run("Notepad.exe")
                Sleep(1000)
                Send($Input4)
                Sleep(1000)
            EndIf

        Case $cButton_2


    EndSwitch
WEnd

Func _ReadFile($sFileName)

    ConsoleWrite(@ScriptDir & "\" & $sFileName & ".txt" & @CRLF)

    ; Read the required file into an array
    Local $aFileContents
    _FileReadToArray(@ScriptDir & "\" & $sFileName & ".txt", $aFileContents)
    ConsoleWrite(@error & @CRLF)
    ; Now transfer the data in that array into one we can use

    ; Firstly resize the global array which we use elsewhere
     Global $aPCData[$aFileContents[0] + 1][3]
    ; And reset the list contents
    Local $sList = ""

    ; Now loop through the data transferring it to the new array and to to the list we display
    For $i = 1 To $aFileContents[0]
        ; Split the line on the spaces
        $aSplit = StringSplit($aFileContents[$i], " ")
        ; And add the 3 parts to the larger array
        $aPCData[$i][0] = $aSplit[2]
        $aPCData[$i][1] = $aSplit[1]
        $aPCData[$i][2] = $aSplit[3]
        ; Then add the name to the list
        $sList &= "|" & $aSplit[2]
    Next

    ; And just for interest, this is what we get in the array
    _ArrayDisplay($aPCData)

    ; Finally return the list to be added to the control in the GUI
    Return $sList

EndFunc

Thanks

Grimm

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

  • Moderators

grimmlock,

Happy New Year!

You were not searching inside the correct array - we (re)create this array dynamically as the combo selection changes: ;)

#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>

; Declare a Global array to hold the data for the currently selected list
Global $aPCData

; There is no need to read the file here - we do it dynamically as the combo selection changes <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Global $aServers[2][2] = [["PC 1", "test.test1.test1"], ["PC 2", "test1.test1.test1"]]

GUICreate("test", 400, 400)
GUISetState(@SW_SHOW)

Local $cCombo = GUICtrlCreateCombo("", 10, 10, 100, 20)
GUICtrlSetData(-1, "List_1|List_2|List_3") ; So you have all the lists able to be selected from the combo ; I saved the file at "List_1.txt" <<<<<<
Local $cList = GUICtrlCreateList("", 10, 50, 100, 50)
Local $cButton_1 = GUICtrlCreateButton("Notepad", 200, 50, 100, 100)
Local $cButton_2 = GUICtrlCreateButton("Wake On Lan", 200, 200, 100, 100)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cCombo
            ; Read the selection
            $sSelection = GUICtrlRead($cCombo)
            ; Open the file and get back a a list
            $sList = _ReadFile($sSelection)
            ; Fill the List with that data
            GUICtrlSetData($cList, $sList)

        Case $cbutton_1
            Local $Input3 = GUICtrlRead($clist)
            ; Find the PC in the array 
            $iIndex = _ArraySearch($aPCData, $Input3) ; Search the dynamically created array <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ; Did we find a match?
            If $iIndex <> -1 Then
                ; Get the associated IP and trim as required
                Local $Input4 = StringTrimRight($aPCData[$iIndex][1], 12) ; And look in the same array for the associated data <<<<<<<<<

                ConsoleWrite($aPCData[$iIndex][1] & @CRLF) ; Just check we have the right one <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                ;Run("Notepad.exe")
                ;Sleep(1000)
                ;Send($Input4)
                ;Sleep(1000)
            EndIf

        Case $cButton_2


    EndSwitch
WEnd

Func _ReadFile($sFileName)

    ConsoleWrite(@ScriptDir & "\" & $sFileName & ".txt" & @CRLF)

    ; Read the required file into an array
    Local $aFileContents
    _FileReadToArray(@ScriptDir & "\" & $sFileName & ".txt", $aFileContents)
    ; Now transfer the data in that array into one we can use

    ; Firstly resize the global array which we use elsewhere
     Global $aPCData[$aFileContents[0] + 1][3]
    ; And reset the list contents
    Local $sList = ""

    ; Now loop through the data transferring it to the new array and to to the list we display
    For $i = 1 To $aFileContents[0]
        ; Split the line on the spaces
        $aSplit = StringSplit($aFileContents[$i], " ")
        ; And add the 3 parts to the larger array
        $aPCData[$i][0] = $aSplit[2]
        $aPCData[$i][1] = $aSplit[1]
        $aPCData[$i][2] = $aSplit[3]
        ; Then add the name to the list
        $sList &= "|" & $aSplit[2]
    Next

    ; And just for interest, this is what we get in the array
   _ArrayDisplay($aPCData)

    ; Finally return the list to be added to the control in the GUI
    Return $sList

EndFunc

Are we getting somewhere or do we need to go back to the very beginning? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

LOL not sure, let me post my entire script. I talked to my co-worker and he said that all the IPs are in a MySQL database. I am having a hard time finding a MySQL connector for Autoit.

I can pull from a file but the files for each location would be stored on a server at each location.

Here is what I have. Keep in mind it is really ugly as I am REALLY trying to clean this up

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GUIComboBox.au3>
#Include <String.au3>


; Declare a flag
Global $fPing = False
Global $Input1 = False
Global $Input2 = False


GUICreate("Am I Asleep?", 315, 850)


GUISetState()

;~ IP Addresses
$List1 = FileRead("c:\dhcp2.txt") ; Branch1
$List2 = FileRead("\server.test1.local\Installers\dhcp2.txt") ; Branch2
$List3 = ("") ; Branch3
$List4 = ("") ; Branch4
$List5 = ("") ; Branch5
$List6 = ("") ; Branch6
$List7 = ("") ; Branch7
$List8 = ("") ; Branch8
$List9 = ("") ; Branch9
$List10 = ("") ;Branch10
$List11 = ("") ; Branch11
$List12 = ("") ; Branch12
$List13 = ("") ; Branch13
$List14 = ("") ; Branch14
$List15 = ("") ; Branch15
$List16 = ("") ; Branch16
$List17 = ("") ; Branch17
$List18 = FileRead("C:\SC_PC.txt") ; Branch18
$List19 = ("") Branch Servers
$List20 = ("") ; Core Servers

;~ Mac Addresses (Would be nice to be able to read from the same file as IP Addresses)
;~ $List21 = ("") ;Branch1 - MAC
;~ $List22 = ("") ;Branch2 - MAC
;~ $List23 = ("") ;Branch3 - MAC
;~ $List24 = ("") ;Branch4 - MAC
;~ $List25 = ("") ;Branch5 - MAC
;~ $List26 = ("") ;Branch6 - MAC
;~ $List27 = ("") ;Branch7 - MAC
;~ $List28 = ("") ;Branch8 - MAC
;~ $List29 = ("") ;Branch9- MAC
;~ $List30 = ("") ;Branch10 - MAC
;~ $List31 = ("") ;Branch11 - MAC
;~ $List32 = ("") ;Branch12 - MAC
;~ $List33 = ("") ;Branch13 - MAC
;~ $List34 = ("") ;Branch14 - MAC
;~ $List35 = ("") ;Branch15 - MAC
;~ $List36 = ("") ;Branch16 - MAC
;~ $List37 = ("") ;Branch17 - MAC
;~ $List38 = ("") ;Branch18 - MAC



Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2|Branch3|Branch4|Branch5|Branch6|Branch7|Branch8|Branch9|Branch10|Branch11|Branch12|Branch13|Branch14|Branch15|Branch16|Branch17|Branch18|Branch Servers|Core Servers")

; Set Cuebanner rather than add an extra element to the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Get handle of combo edit
$tInfo = $tagCOMBOBOXINFO
_GUICtrlComboBox_GetComboBoxInfo($Combo1, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")
; Write CueBanner
$tText = _WinAPI_MultiByteToWideChar("Select one")
_SendMessage($hComboEdit, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*")

Local $Input1 = GUICtrlCreateList("", 150, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $Input2 = GUICtrlCreateList("", 440, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)

;~ Controls
Local $Button_1 = GUICtrlCreateButton("Ping", 10, 340, 115)
Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 10, 380, 115)
Local $Button_3 = GUICtrlCreateButton("Netsupport Manager", 10, 440, 115)
Local $Button_4 = GUICtrlCreateButton("Remote Desktop", 10, 475, 115)
Local $Button_5 = GUICtrlCreateButton("VNC", 10, 510, 115)
Local $Button_6 = GUICtrlCreateButton("Start WHD", 10, 750, 115)
Local $Button_7 = GUICtrlCreateButton("Stop WHD", 10, 780, 115)
Local $Display1 = GUICtrlCreateEdit("", 10, 70, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)
Local $Display2 = GUICtrlCreateEdit("", 10, 110, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)


$iIndex = 0
_GUICtrlListBox_ClickItem($Input1, $iIndex)
$iCount = _GUICtrlListBox_GetCount($Input1)

; _AddHorzSep(10, 40, 290)
_AddHorzSep(10, 325, 125)
_AddHorzSep(10, 420, 125)
;~ _AddHorzSep(10, 690, 125)

; Get a timestamp
$iBegin = TimerInit()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit


Case $Button_1
Switch GUICtrlRead($Button_1)
; What does the button tell us we are going to do?
Case "Ping"
; We need to ping
$fPing = True
; And set the button text accordingly
GUICtrlSetData($Button_1, "Stop")
; Disable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_DISABLE)
Case Else
; Now we need to stop pinging
$fPing = False
; And again change the button text
GUICtrlSetData($Button_1, "Ping")
; Enable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_ENABLE)
EndSwitch


Case $Combo1
Switch GUICtrlRead($Combo1)
Case "Branch1"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch1
GUICtrlSetData($Input1, "|" & $List1)
;~ GUICtrlSetData($Input2, "|" & $List21)
Case "Branch2"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
GUICtrlSetData($Input1, "|" & $List2)
;~ GUICtrlSetData($Input2, "|" & $List22)
Case "Branch3"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch3
GUICtrlSetData($Input1, "|" & $List3)
;~ GUICtrlSetData($Input2, "|" & $List23)
Case "Branch4"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch4
GUICtrlSetData($Input1, "|" & $List4)
;~ GUICtrlSetData($Input2, "|" & $List24)
Case "Branch5"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch5
GUICtrlSetData($Input1, "|" & $List5)
;~ GUICtrlSetData($Input2, "|" & $List25)
Case "Branch6"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch6
GUICtrlSetData($Input1, "|" & $List6)
;~ GUICtrlSetData($Input2, "|" & $List26)
Case "Branch7"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch7
GUICtrlSetData($Input1, "|" & $List7)
;~ GUICtrlSetData($Input2, "|" & $List27)
Case "Branch8"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch8
GUICtrlSetData($Input1, "|" & $List8)
;~ GUICtrlSetData($Input2, "|" & $List28)
Case "Branch9"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch9
GUICtrlSetData($Input1, "|" & $List9)
;~ GUICtrlSetData($Input2, "|" & $List29)
Case "Branch10|"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch10
GUICtrlSetData($Input1, "|" & $List10)
;~ GUICtrlSetData($Input2, "|" & $List30)
Case "Branch11"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch11
GUICtrlSetData($Input1, "|" & $List11)
;~ GUICtrlSetData($Input2, "|" & $List31)
Case "Branch12"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch12
GUICtrlSetData($Input1, "|" & $List12)
;~ GUICtrlSetData($Input2, "|" & $List32)
Case "Branch13"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch13
GUICtrlSetData($Input1, "|" & $List13)
;~ GUICtrlSetData($Input2, "|" & $List33)
Case "Branch14"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch14
GUICtrlSetData($Input1, "|" & $List14)
;~ GUICtrlSetData($Input2, "|" & $List34)
Case "Branch15"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch15
GUICtrlSetData($Input1, "|" & $List15)
;~ GUICtrlSetData($Input2, "|" & $List35)
Case "Branch16"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch16
GUICtrlSetData($Input1, "|" & $List16)
;~ GUICtrlSetData($Input2, "|" & $List36)
Case "Branch17"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch17
GUICtrlSetData($Input1, "|" & $List17)
;~ GUICtrlSetData($Input2, "|" & $List37)
Case "Branch18"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch18
GUICtrlSetData($Input1, "|" & $List18)
;~ GUICtrlSetData($Input2, "|" & $List38)
Case "Branch Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch Servers
GUICtrlSetData($Input1, "|" & $List19)
Case "Core Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Core Servers
GUICtrlSetData($Input1, "|" & $List20)

EndSwitch

; Get new count <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iCount = _GUICtrlListBox_GetCount($Input1)


Case $Button_2
WakeOnLan()


Case $Button_3
If ProcessExists("PCICTLUI.EXE") Then
Netsupport()
Else
Run("C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE", "")
Netsupport()
EndIf


Case $Button_4
RDP()


Case $Button_5
VNC()


Case $Button_6
WHD_Start()


Case $Button_7
WHD_Stop()


EndSwitch

If $fPing Then
; Have we waited long enough since the last ping?
If TimerDiff($iBegin) > 1000 Then ; 1 sec delay
; Click the current item
_GUICtrlListBox_ClickItem($Input1, $iIndex)
; Read the current item
$sItem = GUICtrlRead($Input1)
$var = Ping(GUICtrlRead($Input1), 999)
If $var <> 0 Then
GUICtrlSetData($Display1, $sItem) ; & " - " & $var & " ms")
GUICtrlSetBkColor($Display1, 0x00FF00)
GUICtrlSetColor($Display1, 0x000000)
GUICtrlSetData($Display2, " " & $var & " ms")
GUICtrlSetBkColor($Display2, 0x00FF00)
GUICtrlSetColor($Display2, 0x000000)
Else
GUICtrlSetData($Display1, $sItem)
GUICtrlSetBkColor($Display1, 0)
GUICtrlSetColor($Display1, 0xFFFFFF)
GUICtrlSetData($Display2, "Request Timed Out ")
GUICtrlSetBkColor($Display2, 0)
GUICtrlSetColor($Display2, 0xFFFFFF)
EndIf
; Reset the timestamp for the next ping
$iBegin = TimerInit()
; Increase the index to select the next item
$iIndex = Mod($iIndex + 1, $iCount)
EndIf
EndIf

WEnd

Func _AddHorzSep($iX, $iY, $iW)

GUICtrlCreateLabel("", $iX, $iY, $iW, 1)
GUICtrlSetBkColor(-1, 0x000000)


EndFunc ;==>_AddHorzSep

Func WHD_Start()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_start.bat{Enter}")
EndFunc

Func WHD_Stop()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\ cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_stop.bat{Enter}")
EndFunc

Func VNC()
Run("C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe")
WinWaitActive("VNC Viewer")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc

Func RDP()
Run("mstsc.exe /console")
WinWaitActive("Remote Desktop Connection")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc



Func Netsupport()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
WinActivate("NetSupport : ")
Send("!C{Down}")
Send("Q")
Sleep(1000)
Send("^A")
Sleep(1000)
_local()
Send("{ENTER}")
Sleep(1000)
If WinActive("Security") Then
Send("{Tab}")
Sleep(1000)
Send("password")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Else
Send("!C{Down}")
Send("w{Enter}")

EndIf

EndFunc

Func _local()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
If StringInStr(GuiCtrlRead($Input1), ".local") Then
Send($Input4)
Sleep(1000)
Else
Send($Input3)
Sleep(1000)
EndIf
EndFunc

Func WakeOnLan() ; need to fix this so that it removes all that funky stuff I need it to
$IPAddress = GuiCtrlRead() ; I want to be able to have this use the IP address associated with the computer name in $Input1
$MACAddress = GUICtrlRead() ; I want to be able to have this use the MAC address associated with the computer name in $Input1


UDPStartUp()

$connexion = UDPOpen($IPAddress, 7)
$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
MsgBox(0, "", $res)

UDPCloseSocket($connexion)
UDPShutdown()

EndFunc

; ===================================================================
; Functions
; ===================================================================


; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)

Return Chr(Dec($strHex))

EndFunc

; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)

$MagicPacket = ""
$MACData = ""

For $p = 1 To 11 Step 2
$MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
Next

For $p = 1 To 6
$MagicPacket = HexToChar("ff") & $MagicPacket
Next

For $p = 1 To 16
$MagicPacket = $MagicPacket & $MACData
Next

Return $MagicPacket

EndFunc

Thanks,

Grimm

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

So the 2 things I am really trying to do with this script is when I launch Netsupport, it only works when I send the IP address of the selected computer. Which why I need the help with pulling the IP from a txt file. Also the WoL section need the IP address and the MAC address, which is all in the same text file. The example of Test.Test1.test1 192.168.0.1 00A0B0C0D0 is what each text file looks like only there are more than one line per text file.

I hope this all helps in making sense of what I trying to get help with.

Edited by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

  • 3 weeks later...

I have tried a ton of combinations and when I try to add this code

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;TraySetState(2) ; hide --> not needed

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

While 1
    $msg = GuiGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_MINIMIZE 
            GuiSetState(@SW_HIDE)
            TraySetState(1) ; show
            TraySetToolTip ("My app - click here to restore")

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

To the script in this post, the minimize button does not minimize to the tray. I am confused as to what I am doing wrong. Any suggestions?

Thanks,

Grimm

Thanks

Grimm

Link to comment
Share on other sites

Grimm,

Your posted code was missing some constants. See if this works as expected. Note the wrapper directive.

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
#AutoIt3Wrapper_Add_Constants=n
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;TraySetState(2) ; hide --> not needed

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

While 1
    $msg = GuiGetMsg()

    Select
        Case $msg = $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            TraySetState(1) ; show
            TraySetToolTip ("My app - click here to restore")

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

kylomas

Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Link to comment
Share on other sites

My apologizes I do not think I included the right information

I want to take this code:

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;TraySetState(2) ; hide --> not needed

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

While 1
    $msg = GuiGetMsg()

    Select
        Case $msg = $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            TraySetState(1) ; show
            TraySetToolTip ("My app - click here to restore")

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

and add it to this code:

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GUIComboBox.au3>
#Include <String.au3>


; Declare a flag
Global $fPing = False
Global $Input1 = False
Global $Input2 = False


GUICreate("Am I Asleep?", 315, 850)


GUISetState()

;~ IP Addresses
$List1 = FileRead("c:\dhcp2.txt") ; Branch1
$List2 = FileRead("\server.test1.local\Installers\dhcp2.txt") ; Branch2
$List3 = ("") ; Branch3
$List4 = ("") ; Branch4
$List5 = ("") ; Branch5
$List6 = ("") ; Branch6
$List7 = ("") ; Branch7
$List8 = ("") ; Branch8
$List9 = ("") ; Branch9
$List10 = ("") ;Branch10
$List11 = ("") ; Branch11
$List12 = ("") ; Branch12
$List13 = ("") ; Branch13
$List14 = ("") ; Branch14
$List15 = ("") ; Branch15
$List16 = ("") ; Branch16
$List17 = ("") ; Branch17
$List18 = FileRead("C:\SC_PC.txt") ; Branch18
$List19 = ("") Branch Servers
$List20 = ("") ; Core Servers

;~ Mac Addresses (Would be nice to be able to read from the same file as IP Addresses)
;~ $List21 = ("") ;Branch1 - MAC
;~ $List22 = ("") ;Branch2 - MAC
;~ $List23 = ("") ;Branch3 - MAC
;~ $List24 = ("") ;Branch4 - MAC
;~ $List25 = ("") ;Branch5 - MAC
;~ $List26 = ("") ;Branch6 - MAC
;~ $List27 = ("") ;Branch7 - MAC
;~ $List28 = ("") ;Branch8 - MAC
;~ $List29 = ("") ;Branch9- MAC
;~ $List30 = ("") ;Branch10 - MAC
;~ $List31 = ("") ;Branch11 - MAC
;~ $List32 = ("") ;Branch12 - MAC
;~ $List33 = ("") ;Branch13 - MAC
;~ $List34 = ("") ;Branch14 - MAC
;~ $List35 = ("") ;Branch15 - MAC
;~ $List36 = ("") ;Branch16 - MAC
;~ $List37 = ("") ;Branch17 - MAC
;~ $List38 = ("") ;Branch18 - MAC



Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2|Branch3|Branch4|Branch5|Branch6|Branch7|Branch8|Branch9|Branch10|Branch11|Branch12|Branch13|Branch14|Branch15|Branch16|Branch17|Branch18|Branch Servers|Core Servers")

; Set Cuebanner rather than add an extra element to the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Get handle of combo edit
$tInfo = $tagCOMBOBOXINFO
_GUICtrlComboBox_GetComboBoxInfo($Combo1, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")
; Write CueBanner
$tText = _WinAPI_MultiByteToWideChar("Select one")
_SendMessage($hComboEdit, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*")

Local $Input1 = GUICtrlCreateList("", 150, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $Input2 = GUICtrlCreateList("", 440, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)

;~ Controls
Local $Button_1 = GUICtrlCreateButton("Ping", 10, 340, 115)
Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 10, 380, 115)
Local $Button_3 = GUICtrlCreateButton("Netsupport Manager", 10, 440, 115)
Local $Button_4 = GUICtrlCreateButton("Remote Desktop", 10, 475, 115)
Local $Button_5 = GUICtrlCreateButton("VNC", 10, 510, 115)
Local $Button_6 = GUICtrlCreateButton("Start WHD", 10, 750, 115)
Local $Button_7 = GUICtrlCreateButton("Stop WHD", 10, 780, 115)
Local $Display1 = GUICtrlCreateEdit("", 10, 70, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)
Local $Display2 = GUICtrlCreateEdit("", 10, 110, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)


$iIndex = 0
_GUICtrlListBox_ClickItem($Input1, $iIndex)
$iCount = _GUICtrlListBox_GetCount($Input1)

; _AddHorzSep(10, 40, 290)
_AddHorzSep(10, 325, 125)
_AddHorzSep(10, 420, 125)
;~ _AddHorzSep(10, 690, 125)

; Get a timestamp
$iBegin = TimerInit()

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit


Case $Button_1
Switch GUICtrlRead($Button_1)
; What does the button tell us we are going to do?
Case "Ping"
; We need to ping
$fPing = True
; And set the button text accordingly
GUICtrlSetData($Button_1, "Stop")
; Disable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_DISABLE)
Case Else
; Now we need to stop pinging
$fPing = False
; And again change the button text
GUICtrlSetData($Button_1, "Ping")
; Enable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetState($Combo1, $GUI_ENABLE)
EndSwitch


Case $Combo1
Switch GUICtrlRead($Combo1)
Case "Branch1"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch1
GUICtrlSetData($Input1, "|" & $List1)
;~ GUICtrlSetData($Input2, "|" & $List21)
Case "Branch2"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
GUICtrlSetData($Input1, "|" & $List2)
;~ GUICtrlSetData($Input2, "|" & $List22)
Case "Branch3"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch3
GUICtrlSetData($Input1, "|" & $List3)
;~ GUICtrlSetData($Input2, "|" & $List23)
Case "Branch4"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch4
GUICtrlSetData($Input1, "|" & $List4)
;~ GUICtrlSetData($Input2, "|" & $List24)
Case "Branch5"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch5
GUICtrlSetData($Input1, "|" & $List5)
;~ GUICtrlSetData($Input2, "|" & $List25)
Case "Branch6"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch6
GUICtrlSetData($Input1, "|" & $List6)
;~ GUICtrlSetData($Input2, "|" & $List26)
Case "Branch7"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch7
GUICtrlSetData($Input1, "|" & $List7)
;~ GUICtrlSetData($Input2, "|" & $List27)
Case "Branch8"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch8
GUICtrlSetData($Input1, "|" & $List8)
;~ GUICtrlSetData($Input2, "|" & $List28)
Case "Branch9"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch9
GUICtrlSetData($Input1, "|" & $List9)
;~ GUICtrlSetData($Input2, "|" & $List29)
Case "Branch10|"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch10
GUICtrlSetData($Input1, "|" & $List10)
;~ GUICtrlSetData($Input2, "|" & $List30)
Case "Branch11"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch11
GUICtrlSetData($Input1, "|" & $List11)
;~ GUICtrlSetData($Input2, "|" & $List31)
Case "Branch12"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch12
GUICtrlSetData($Input1, "|" & $List12)
;~ GUICtrlSetData($Input2, "|" & $List32)
Case "Branch13"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch13
GUICtrlSetData($Input1, "|" & $List13)
;~ GUICtrlSetData($Input2, "|" & $List33)
Case "Branch14"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch14
GUICtrlSetData($Input1, "|" & $List14)
;~ GUICtrlSetData($Input2, "|" & $List34)
Case "Branch15"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch15
GUICtrlSetData($Input1, "|" & $List15)
;~ GUICtrlSetData($Input2, "|" & $List35)
Case "Branch16"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch16
GUICtrlSetData($Input1, "|" & $List16)
;~ GUICtrlSetData($Input2, "|" & $List36)
Case "Branch17"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch17
GUICtrlSetData($Input1, "|" & $List17)
;~ GUICtrlSetData($Input2, "|" & $List37)
Case "Branch18"
ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch18
GUICtrlSetData($Input1, "|" & $List18)
;~ GUICtrlSetData($Input2, "|" & $List38)
Case "Branch Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch Servers
GUICtrlSetData($Input1, "|" & $List19)
Case "Core Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Core Servers
GUICtrlSetData($Input1, "|" & $List20)

EndSwitch

; Get new count <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iCount = _GUICtrlListBox_GetCount($Input1)


Case $Button_2
WakeOnLan()


Case $Button_3
If ProcessExists("PCICTLUI.EXE") Then
Netsupport()
Else
Run("C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE", "")
Netsupport()
EndIf


Case $Button_4
RDP()


Case $Button_5
VNC()


Case $Button_6
WHD_Start()


Case $Button_7
WHD_Stop()


EndSwitch

If $fPing Then
; Have we waited long enough since the last ping?
If TimerDiff($iBegin) > 1000 Then ; 1 sec delay
; Click the current item
_GUICtrlListBox_ClickItem($Input1, $iIndex)
; Read the current item
$sItem = GUICtrlRead($Input1)
$var = Ping(GUICtrlRead($Input1), 999)
If $var <> 0 Then
GUICtrlSetData($Display1, $sItem) ; & " - " & $var & " ms")
GUICtrlSetBkColor($Display1, 0x00FF00)
GUICtrlSetColor($Display1, 0x000000)
GUICtrlSetData($Display2, " " & $var & " ms")
GUICtrlSetBkColor($Display2, 0x00FF00)
GUICtrlSetColor($Display2, 0x000000)
Else
GUICtrlSetData($Display1, $sItem)
GUICtrlSetBkColor($Display1, 0)
GUICtrlSetColor($Display1, 0xFFFFFF)
GUICtrlSetData($Display2, "Request Timed Out ")
GUICtrlSetBkColor($Display2, 0)
GUICtrlSetColor($Display2, 0xFFFFFF)
EndIf
; Reset the timestamp for the next ping
$iBegin = TimerInit()
; Increase the index to select the next item
$iIndex = Mod($iIndex + 1, $iCount)
EndIf
EndIf

WEnd

Func _AddHorzSep($iX, $iY, $iW)

GUICtrlCreateLabel("", $iX, $iY, $iW, 1)
GUICtrlSetBkColor(-1, 0x000000)


EndFunc ;==>_AddHorzSep

Func WHD_Start()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_start.bat{Enter}")
EndFunc

Func WHD_Stop()
Run("cmd.exe")
Sleep(1000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd pstools{Enter}")
Sleep(1000)
Send("psexec \\192.168.26.17\ cmd.exe{Enter}")
Sleep(5000)
Send("cd /{Enter}")
Sleep(1000)
Send("cd Program Files\WebHelpDesk{Enter}")
Sleep(1000)
Send("whd_stop.bat{Enter}")
EndFunc

Func VNC()
Run("C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe")
WinWaitActive("VNC Viewer")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc

Func RDP()
Run("mstsc.exe /console")
WinWaitActive("Remote Desktop Connection")
Send(GUICtrlRead($Input1))
Sleep(1000)
Send("{ENTER}")
EndFunc



Func Netsupport()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
WinActivate("NetSupport : ")
Send("!C{Down}")
Send("Q")
Sleep(1000)
Send("^A")
Sleep(1000)
_local()
Send("{ENTER}")
Sleep(1000)
If WinActive("Security") Then
Send("{Tab}")
Sleep(1000)
Send("password")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Else
Send("!C{Down}")
Send("w{Enter}")

EndIf

EndFunc

Func _local()
Local $Input3 = GUICtrlRead($Input1)
Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
If StringInStr(GuiCtrlRead($Input1), ".local") Then
Send($Input4)
Sleep(1000)
Else
Send($Input3)
Sleep(1000)
EndIf
EndFunc

Func WakeOnLan() ; need to fix this so that it removes all that funky stuff I need it to
$IPAddress = GuiCtrlRead() ; I want to be able to have this use the IP address associated with the computer name in $Input1
$MACAddress = GUICtrlRead() ; I want to be able to have this use the MAC address associated with the computer name in $Input1


UDPStartUp()

$connexion = UDPOpen($IPAddress, 7)
$res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
MsgBox(0, "", $res)

UDPCloseSocket($connexion)
UDPShutdown()

EndFunc

; ===================================================================
; Functions
; ===================================================================


; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)

Return Chr(Dec($strHex))

EndFunc

; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)

$MagicPacket = ""
$MACData = ""

For $p = 1 To 11 Step 2
$MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
Next

For $p = 1 To 6
$MagicPacket = HexToChar("ff") & $MagicPacket
Next

For $p = 1 To 16
$MagicPacket = $MagicPacket & $MACData
Next

Return $MagicPacket

EndFunc

The addition of the minimize to tray code is my issue. No matter how I add it to the second code it will not minimize to the tray.

Thanks

Grimm

Link to comment
Share on other sites

Grimm,

Try this

#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GUIComboBox.au3>
#include <String.au3>

#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;TraySetState(2) ; hide --> not needed

; Declare a flag
Global $fPing = False
Global $Input1 = False
Global $Input2 = False


GUICreate("Am I Asleep?", 315, 850)


GUISetState()

;~ IP Addresses
$List1 = FileRead("c:\dhcp2.txt") ; Branch1
$List2 = FileRead("\server.test1.local\Installers\dhcp2.txt") ; Branch2
$List3 = ("") ; Branch3
$List4 = ("") ; Branch4
$List5 = ("") ; Branch5
$List6 = ("") ; Branch6
$List7 = ("") ; Branch7
$List8 = ("") ; Branch8
$List9 = ("") ; Branch9
$List10 = ("") ;Branch10
$List11 = ("") ; Branch11
$List12 = ("") ; Branch12
$List13 = ("") ; Branch13
$List14 = ("") ; Branch14
$List15 = ("") ; Branch15
$List16 = ("") ; Branch16
$List17 = ("") ; Branch17
$List18 = FileRead("C:\SC_PC.txt") ; Branch18
$List19 = ("") ;Branch Servers
$List20 = ("") ; Core Servers

;~ Mac Addresses (Would be nice to be able to read from the same file as IP Addresses)
;~ $List21 = ("") ;Branch1 - MAC
;~ $List22 = ("") ;Branch2 - MAC
;~ $List23 = ("") ;Branch3 - MAC
;~ $List24 = ("") ;Branch4 - MAC
;~ $List25 = ("") ;Branch5 - MAC
;~ $List26 = ("") ;Branch6 - MAC
;~ $List27 = ("") ;Branch7 - MAC
;~ $List28 = ("") ;Branch8 - MAC
;~ $List29 = ("") ;Branch9- MAC
;~ $List30 = ("") ;Branch10 - MAC
;~ $List31 = ("") ;Branch11 - MAC
;~ $List32 = ("") ;Branch12 - MAC
;~ $List33 = ("") ;Branch13 - MAC
;~ $List34 = ("") ;Branch14 - MAC
;~ $List35 = ("") ;Branch15 - MAC
;~ $List36 = ("") ;Branch16 - MAC
;~ $List37 = ("") ;Branch17 - MAC
;~ $List38 = ("") ;Branch18 - MAC



Local $Combo1 = GUICtrlCreateCombo("", 10, 20, 125, 10)
GUICtrlSetData(-1, "Branch1|Branch2|Branch3|Branch4|Branch5|Branch6|Branch7|Branch8|Branch9|Branch10|Branch11|Branch12|Branch13|Branch14|Branch15|Branch16|Branch17|Branch18|Branch Servers|Core Servers")

; Set Cuebanner rather than add an extra element to the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Get handle of combo edit
$tInfo = $tagCOMBOBOXINFO
_GUICtrlComboBox_GetComboBoxInfo($Combo1, $tInfo)
$hComboEdit = DllStructGetData($tInfo, "hEdit")
; Write CueBanner
$tText = _WinAPI_MultiByteToWideChar("Select one")
_SendMessage($hComboEdit, $EM_SETCUEBANNER, False, $tText, 0, "wparam", "struct*")

Local $Input1 = GUICtrlCreateList("", 150, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
Local $Input2 = GUICtrlCreateList("", 440, 20, 150, 815, BitOR($ES_READONLY, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)

;~ Controls
Local $Button_1 = GUICtrlCreateButton("Ping", 10, 340, 115)
Local $Button_2 = GUICtrlCreateButton("Wake On Lan", 10, 380, 115)
Local $Button_3 = GUICtrlCreateButton("Netsupport Manager", 10, 440, 115)
Local $Button_4 = GUICtrlCreateButton("Remote Desktop", 10, 475, 115)
Local $Button_5 = GUICtrlCreateButton("VNC", 10, 510, 115)
Local $Button_6 = GUICtrlCreateButton("Start WHD", 10, 750, 115)
Local $Button_7 = GUICtrlCreateButton("Stop WHD", 10, 780, 115)
Local $Display1 = GUICtrlCreateEdit("", 10, 70, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)
Local $Display2 = GUICtrlCreateEdit("", 10, 110, 125, 30, BitOR($ES_READONLY, $ES_CENTER)) ;, 0)


$iIndex = 0
_GUICtrlListBox_ClickItem($Input1, $iIndex)
$iCount = _GUICtrlListBox_GetCount($Input1)

; _AddHorzSep(10, 40, 290)
_AddHorzSep(10, 325, 125)
_AddHorzSep(10, 420, 125)
;~ _AddHorzSep(10, 690, 125)

; Get a timestamp
$iBegin = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            TraySetState(1) ; show
            TraySetToolTip ("My app - click here to restore")

        Case $Button_1
            Switch GUICtrlRead($Button_1)
                ; What does the button tell us we are going to do?
                Case "Ping"
                    ; We need to ping
                    $fPing = True
                    ; And set the button text accordingly
                    GUICtrlSetData($Button_1, "Stop")
                    ; Disable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    GUICtrlSetState($Combo1, $GUI_DISABLE)
                Case Else
                    ; Now we need to stop pinging
                    $fPing = False
                    ; And again change the button text
                    GUICtrlSetData($Button_1, "Ping")
                    ; Enable the combo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    GUICtrlSetState($Combo1, $GUI_ENABLE)
            EndSwitch


        Case $Combo1
            Switch GUICtrlRead($Combo1)
                Case "Branch1"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch1
                    GUICtrlSetData($Input1, "|" & $List1)
;~ GUICtrlSetData($Input2, "|" & $List21)
                Case "Branch2"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch2
                    GUICtrlSetData($Input1, "|" & $List2)
;~ GUICtrlSetData($Input2, "|" & $List22)
                Case "Branch3"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch3
                    GUICtrlSetData($Input1, "|" & $List3)
;~ GUICtrlSetData($Input2, "|" & $List23)
                Case "Branch4"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch4
                    GUICtrlSetData($Input1, "|" & $List4)
;~ GUICtrlSetData($Input2, "|" & $List24)
                Case "Branch5"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch5
                    GUICtrlSetData($Input1, "|" & $List5)
;~ GUICtrlSetData($Input2, "|" & $List25)
                Case "Branch6"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch6
                    GUICtrlSetData($Input1, "|" & $List6)
;~ GUICtrlSetData($Input2, "|" & $List26)
                Case "Branch7"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch7
                    GUICtrlSetData($Input1, "|" & $List7)
;~ GUICtrlSetData($Input2, "|" & $List27)
                Case "Branch8"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch8
                    GUICtrlSetData($Input1, "|" & $List8)
;~ GUICtrlSetData($Input2, "|" & $List28)
                Case "Branch9"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch9
                    GUICtrlSetData($Input1, "|" & $List9)
;~ GUICtrlSetData($Input2, "|" & $List29)
                Case "Branch10|"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch10
                    GUICtrlSetData($Input1, "|" & $List10)
;~ GUICtrlSetData($Input2, "|" & $List30)
                Case "Branch11"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch11
                    GUICtrlSetData($Input1, "|" & $List11)
;~ GUICtrlSetData($Input2, "|" & $List31)
                Case "Branch12"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch12
                    GUICtrlSetData($Input1, "|" & $List12)
;~ GUICtrlSetData($Input2, "|" & $List32)
                Case "Branch13"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch13
                    GUICtrlSetData($Input1, "|" & $List13)
;~ GUICtrlSetData($Input2, "|" & $List33)
                Case "Branch14"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch14
                    GUICtrlSetData($Input1, "|" & $List14)
;~ GUICtrlSetData($Input2, "|" & $List34)
                Case "Branch15"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch15
                    GUICtrlSetData($Input1, "|" & $List15)
;~ GUICtrlSetData($Input2, "|" & $List35)
                Case "Branch16"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch16
                    GUICtrlSetData($Input1, "|" & $List16)
;~ GUICtrlSetData($Input2, "|" & $List36)
                Case "Branch17"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch17
                    GUICtrlSetData($Input1, "|" & $List17)
;~ GUICtrlSetData($Input2, "|" & $List37)
                Case "Branch18"
                    ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch18
                    GUICtrlSetData($Input1, "|" & $List18)
;~ GUICtrlSetData($Input2, "|" & $List38)
                Case "Branch Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Branch Servers
                    GUICtrlSetData($Input1, "|" & $List19)
                Case "Core Servers"
;~ ConsoleWrite("Hit" & @CRLF) ; <<<<<<<<<<<<< Core Servers
                    GUICtrlSetData($Input1, "|" & $List20)

            EndSwitch

            ; Get new count <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $iCount = _GUICtrlListBox_GetCount($Input1)


        Case $Button_2
            WakeOnLan()


        Case $Button_3
            If ProcessExists("PCICTLUI.EXE") Then
                Netsupport()
            Else
                Run("C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE", "")
                Netsupport()
            EndIf


        Case $Button_4
            RDP()


        Case $Button_5
            VNC()


        Case $Button_6
            WHD_Start()


        Case $Button_7
            WHD_Stop()


    EndSwitch

    If $fPing Then
        ; Have we waited long enough since the last ping?
        If TimerDiff($iBegin) > 1000 Then ; 1 sec delay
            ; Click the current item
            _GUICtrlListBox_ClickItem($Input1, $iIndex)
            ; Read the current item
            $sItem = GUICtrlRead($Input1)
            $var = Ping(GUICtrlRead($Input1), 999)
            If $var <> 0 Then
                GUICtrlSetData($Display1, $sItem) ; & " - " & $var & " ms")
                GUICtrlSetBkColor($Display1, 0x00FF00)
                GUICtrlSetColor($Display1, 0x000000)
                GUICtrlSetData($Display2, " " & $var & " ms")
                GUICtrlSetBkColor($Display2, 0x00FF00)
                GUICtrlSetColor($Display2, 0x000000)
            Else
                GUICtrlSetData($Display1, $sItem)
                GUICtrlSetBkColor($Display1, 0)
                GUICtrlSetColor($Display1, 0xFFFFFF)
                GUICtrlSetData($Display2, "Request Timed Out ")
                GUICtrlSetBkColor($Display2, 0)
                GUICtrlSetColor($Display2, 0xFFFFFF)
            EndIf
            ; Reset the timestamp for the next ping
            $iBegin = TimerInit()
            ; Increase the index to select the next item
            $iIndex = Mod($iIndex + 1, $iCount)
        EndIf
    EndIf

WEnd

Func _AddHorzSep($iX, $iY, $iW)

    GUICtrlCreateLabel("", $iX, $iY, $iW, 1)
    GUICtrlSetBkColor(-1, 0x000000)


EndFunc   ;==>_AddHorzSep

Func WHD_Start()
    Run("cmd.exe")
    Sleep(1000)
    Send("cd /{Enter}")
    Sleep(1000)
    Send("cd pstools{Enter}")
    Sleep(1000)
    Send("psexec \\192.168.26.17\cmd.exe{Enter}")
    Sleep(5000)
    Send("cd /{Enter}")
    Sleep(1000)
    Send("cd Program Files\WebHelpDesk{Enter}")
    Sleep(1000)
    Send("whd_start.bat{Enter}")
EndFunc   ;==>WHD_Start

Func WHD_Stop()
    Run("cmd.exe")
    Sleep(1000)
    Send("cd /{Enter}")
    Sleep(1000)
    Send("cd pstools{Enter}")
    Sleep(1000)
    Send("psexec \\192.168.26.17\ cmd.exe{Enter}")
    Sleep(5000)
    Send("cd /{Enter}")
    Sleep(1000)
    Send("cd Program Files\WebHelpDesk{Enter}")
    Sleep(1000)
    Send("whd_stop.bat{Enter}")
EndFunc   ;==>WHD_Stop

Func VNC()
    Run("C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe")
    WinWaitActive("VNC Viewer")
    Send(GUICtrlRead($Input1))
    Sleep(1000)
    Send("{ENTER}")
EndFunc   ;==>VNC

Func RDP()
    Run("mstsc.exe /console")
    WinWaitActive("Remote Desktop Connection")
    Send(GUICtrlRead($Input1))
    Sleep(1000)
    Send("{ENTER}")
EndFunc   ;==>RDP



Func Netsupport()
    Local $Input3 = GUICtrlRead($Input1)
    Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
    WinActivate("NetSupport : ")
    Send("!C{Down}")
    Send("Q")
    Sleep(1000)
    Send("^A")
    Sleep(1000)
    _local()
    Send("{ENTER}")
    Sleep(1000)
    If WinActive("Security") Then
        Send("{Tab}")
        Sleep(1000)
        Send("password")
        Sleep(2000)
        Send("{Enter}")
        Sleep(1000)
    Else
        Send("!C{Down}")
        Send("w{Enter}")

    EndIf

EndFunc   ;==>Netsupport

Func _local()
    Local $Input3 = GUICtrlRead($Input1)
    Local $Input4 = StringTrimRight(GUICtrlRead($Input1), 12)
    If StringInStr(GUICtrlRead($Input1), ".local") Then
        Send($Input4)
        Sleep(1000)
    Else
        Send($Input3)
        Sleep(1000)
    EndIf
EndFunc   ;==>_local

Func WakeOnLan() ; need to fix this so that it removes all that funky stuff I need it to
    ;$IPAddress = GUICtrlRead() ; I want to be able to have this use the IP address associated with the computer name in $Input1
    ;$MACAddress = GUICtrlRead() ; I want to be able to have this use the MAC address associated with the computer name in $Input1


;~  UDPStartup()

;~  $connexion = UDPOpen($IPAddress, 7)
;~  $res = UDPSend($connexion, GenerateMagicPacket($MACAddress))
;~  MsgBox(0, "", $res)

;~  UDPCloseSocket($connexion)
;~  UDPShutdown()

EndFunc   ;==>WakeOnLan

; ===================================================================
; Functions
; ===================================================================


; This function convert a MAC Address Byte (e.g. "1f") to a char
Func HexToChar($strHex)

    Return Chr(Dec($strHex))

EndFunc   ;==>HexToChar

; This function generate the "Magic Packet"
Func GenerateMagicPacket($strMACAddress)

    $MagicPacket = ""
    $MACData = ""

    For $p = 1 To 11 Step 2
        $MACData = $MACData & HexToChar(StringMid($strMACAddress, $p, 2))
    Next

    For $p = 1 To 6
        $MagicPacket = HexToChar("ff") & $MagicPacket
    Next

    For $p = 1 To 16
        $MagicPacket = $MagicPacket & $MACData
    Next

    Return $MagicPacket

EndFunc   ;==>GenerateMagicPacket

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

kylomas

Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Link to comment
Share on other sites

Glad it worked, some suggestions...

You should consider externalizing the ip/mac data, file, ini, db, whatever. This will ease maintenance down the road.

You should also utilize arrays more.

Good Luck,

kylomas

Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Link to comment
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
 Share

×
×
  • Create New...