Jump to content

Recommended Posts

Posted

2IN1 Connections..It's easy use for connect to internet and ping web or first online with Google. :)

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode",1)

Global $hForm, $Progress, $Button1, $Button2, $Button3
Global $exititem, $msg, $sCurr1, $sCurr2, $allping
Global $keyname = 'HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{EF29A0E7-C8AC-4982-A287-1952F9A35DF0}'
Global $valuename = 'DhcpIPAddress'
Global $host1 = 'www.21call.com',  $host2 = 'www.dtac.com'
Global $pic, $pid
Global $var, $varping, $url = 'www.google.co.th'
Global $time = 2000
$hForm = GUICreate("Mini Line Connections", 201, 36, 819, 698, BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
GUISetBkColor(0xE3E3E3)
$Progress = GUICtrlCreateProgress(0, 0, 200, 17, -1, BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
$Button1 = GUICtrlCreateButton("Connections", 49, 17, 118, 20, BitOR($BS_CENTER,$WS_GROUP))
GUICtrlSetOnEvent(-1, "connections")
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Google", 0, 17, 50, 20, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_google")
GUICtrlSetCursor (-1, 0)
$Button3 = GUICtrlCreateButton("Ping", 166, 17, 35, 20, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_ping")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)

TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
    $msg = TrayGetMsg()
    Switch $msg
        Case 0
            If RegRead($keyname, $valuename) = '0.0.0.0' Then
                GUICtrlSetData($Progress, 0)
                GUICtrlSetState($Button1, $GUI_ENABLE)
                Sleep(1000)
            Else
                $sCurr1 = ping($host1, 4000)
                If $sCurr1 Then
                    $sCurr2 = ping($host2, 4000)
                    $allping = $sCurr1+$sCurr2
                EndIf
                If $allping <= 0 Then
                    GUICtrlSetData($Progress, 0)
                ElseIf $allping >= 2000 Then
                    GUICtrlSetData($Progress, 25)
                ElseIf $allping >= 3000 Then
                    GUICtrlSetData($Progress, 55)
                ElseIf $allping >= 4000 Then
                    GUICtrlSetData($Progress, 85)
                ElseIf $allping >= 5000 Then
                    GUICtrlSetData($Progress, 100)
                Else
                    GUICtrlSetData($Progress, $allping/20)
                EndIf
            EndIf
        Case $exititem
            ExitLoop
    EndSwitch
WEnd

Func connections()
If @IPAddress1 = '127.0.0.1' Then
    GUICtrlSetState($Button1, $GUI_DISABLE)
    ToolTip('Connecting...', 880, 678)
    $pic = Run(@ComSpec & " /C " & 'rasphone.exe', "", @SW_HIDE)
    WinWaitActive("Network Connections", "Choose a network connection:", 1)
    Send("{ENTER}")
    If ProcessWaitClose($pic) Then
        WinClose("Network Connections")
        ToolTip('')
        GUICtrlSetState($Button1, $GUI_ENABLE)
    EndIf
Else
    GUICtrlSetState($Button1, $GUI_DISABLE)
    ToolTip('Disconnect', 880, 678)
    $pid = Run(@ComSpec & " /C " & 'rasdial /disconnect', "", @SW_HIDE)
    If ProcessWaitClose($pid) Then
        GUICtrlSetState($Button1, $GUI_ENABLE)
        Sleep($time)
        ToolTip('')
    EndIf
EndIf
EndFunc

Func _ping()
If @IPAddress1 = '127.0.0.1' Then
    MsgBox(0, "", "กรุณาต่ออินเทอร์เน็ต.")
Else
    While 1
        $var = InputBox("Ping Web Manager", "Enter:URL name", Default, "", 200, 100, 410, 300)
        If @error Then
            ExitLoop
        Else
            If $var = '' Then
                MsgBox(0, "", "กรุณาเติมลิ๊งค์เว็บไซด์ลงในช่อง.")
                ContinueLoop
            Else
                ToolTip("โปรดรอสักครู่...", 400, 300)
                $varping = Ping($var, 4000)
                If $varping <> 0 Then
                    ToolTip("")
                    MsgBox(0, "Ping Report", $var&'='&$varping&@CRLF&'ติดต่อสำเร็จ.')
                Else
                    ToolTip("")
                    MsgBox(0, "Ping Report", $var&'='&$varping&@CRLF&'ไม่สามารถติดต่อได้.')
                EndIf
            EndIf
        EndIf
    WEnd
EndIf
EndFunc

Func _google()
If @IPAddress1 = '127.0.0.1' Then
    MsgBox(0, "", "กรุณาต่ออินเทอร์เน็ต.")
Else
    ShellExecute($url)
EndIf
EndFunc

post-63570-0-21117600-1299606927_thumb.j

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...