Код:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <GuiIPAddress.au3>
#include <WindowsConstants.au3>
Global $nForm, $hIPAddress, $sLastIP, $Timer
Global $START_IP = "127.0.0.1"
Global $WAITING = 10
Global $PROCESS_WELL_PC = 'pr_1.exe'
Global $PROCESS_BAD_PC = 'pr_2.exe'
Global $GLOBAL_IP = $START_IP
Opt("TrayMenuMode", 1)
$Timer = TimerInit()
$hIp = TrayCreateItem("IP Ping")
TrayCreateItem("")
$hExit = TrayCreateItem("Exit")
TraySetState()
TraySetIcon("shell32.dll", 156)
While 1
$msg = TrayGetMsg()
Switch $msg
Case $hIp
TrayItemSetState($hIp, $TRAY_UNCHECKED + $TRAY_DISABLE)
TrayItemSetState($hExit, $TRAY_DISABLE)
$sIP = _GuiCreate()
If Not (@error) Then $GLOBAL_IP = $sIP
TrayItemSetState($hIp, $TRAY_ENABLE)
TrayItemSetState($hExit, $TRAY_ENABLE)
Case $hExit
Exit
Case Else
If (Round(TimerDiff($Timer) / 1000)) > $WAITING Then
ConsoleWrite('ping - ' & $GLOBAL_IP & @CRLF)
$Ping = Ping($GLOBAL_IP)
$Error = @error
$Hint = _ErrorPing($Error)
If $Ping = 0 Then
_IpPingBadPC($Hint)
Else
_IpPingWellPC($Hint)
EndIf
$Timer = TimerInit()
EndIf
EndSwitch
WEnd
Func _IpPingWellPC($Hint = '')
TraySetIcon("shell32.dll", 239)
TraySetToolTip($Hint)
If Not ProcessExists($PROCESS_WELL_PC) Then Run(@ComSpec & " /C sc start служба", "", @SW_HIDE)
EndFunc ;==>_IpPingWellPC
Func _IpPingBadPC($Hint = '') ;если машины нет в сети...
TraySetIcon("shell32.dll", 338)
TraySetToolTip($Hint)
If ProcessExists($PROCESS_BAD_PC) Then Run(@ComSpec & " /C sc stop служба", "", @SW_HIDE)
EndFunc ;==>_IpPingBadPC
Func _ErrorPing($Error = 0)
Switch $Error
Case 1
Return "Xост работает в автономном режиме"
Case 2
Return "Xост недостижим"
Case 3
Return "Xост неверно указан"
Case 4
Return "Другие ошибки"
Case Else
Return "Xост Онлайн"
EndSwitch
EndFunc ;==>_ErrorPing
Func _GuiCreate()
$nForm = GUICreate("", 223, 102, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$hIPAddress = _GUICtrlIpAddress_Create($nForm, 24, 16, 162, 21)
If Not $sLastIP Then
_GUICtrlIpAddress_Set($hIPAddress, $START_IP)
Else
_GUICtrlIpAddress_Set($hIPAddress, $sLastIP)
EndIf
$Button1 = GUICtrlCreateButton("Ok", 144, 64, 43, 25)
$Button2 = GUICtrlCreateButton("Cancel", 64, 64, 75, 25)
GUISetState(@SW_SHOW, $nForm)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button2
GUIDelete($nForm)
Return SetError(1, 0, 0)
Case $Button1
$sLastIP = _GUICtrlIpAddress_Get($hIPAddress)
GUIDelete($nForm)
Return $sLastIP
EndSwitch
WEnd
EndFunc ;==>_GuiCreate