Jump to content

How To Disable And Enable Network Connection With Autoit


kmps
 Share

Recommended Posts

sorry,

Your script can't work when the user use static IP config

Run(@Comspec & ' /c ' & "ipconfig /release","", @SW_HIDE)

Run(@Comspec & ' /c ' & "ipconfig /renew","", @SW_HIDE)

:think: had to test it and of course screwed me up when i released it hahahahah

Link to comment
Share on other sites

netsh interface set interface name="Local Area Connection" admin=DISABLED

netsh interface set interface name="Local Area Connection" admin=ENABLED

the two cmd above seemed to work,but I failed and the error message as below:

没有指定一个或多个关键性参数

此命令提供的语法不正确。请查看帮助以获取正确的语法信息。

用法 set interface [name = ] IfName

[ [admin = ] ENABLED|DISABLED

[connect = ] CONNECTED|DISCONNECTED

[newname = ] NewName ]

设置接口参数。

IfName - 接口名称

admin - 接口是否被启用 (仅用于非 LAN)。

connect - 是否连接接口 (仅用于非 LAN)。

newname - 接口的新名称 (仅用于非 LAN)。

注意:

- 除名称外,还必须至少指定一个选项。

- 如果 connect = CONNECTED 被指定,那么接口被自动

启用,甚至在 admin = DISABLED 选项被指定时也是如

此。

why????

Link to comment
Share on other sites

I found this command couldn't run correctly under Windows XP.and I solved it by run Microsoft's DEVCON.EXE (Google can find it and download it)

devcon.exe disable =net pci\*

devcon.exe enable =net pci\*

netsh interface set interface name="Local Area Connection" admin=DISABLED

netsh interface set interface name="Local Area Connection" admin=ENABLED

the two cmd above seemed to work,but I failed and the error message as below:

没有指定一个或多个关键性参数

此命令提供的语法不正确。请查看帮助以获取正确的语法信息。

用法 set interface [name = ] IfName

[ [admin = ] ENABLED|DISABLED

[connect = ] CONNECTED|DISCONNECTED

[newname = ] NewName ]

设置接口参数。

IfName - 接口名称

admin - 接口是否被启用 (仅用于非 LAN)。

connect - 是否连接接口 (仅用于非 LAN)。

newname - 接口的新名称 (仅用于非 LAN)。

注意:

- 除名称外,还必须至少指定一个选项。

- 如果 connect = CONNECTED 被指定,那么接口被自动

启用,甚至在 admin = DISABLED 选项被指定时也是如

此。

why????

Link to comment
Share on other sites

  • 4 years later...

Example:Mobile Net Connections Script :unsure:

#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>

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 = @ProgramFilesDir&'\Mozilla Firefox 4.0 Beta 7\firefox.exe'
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 @error
            If RegRead($keyname, $valuename) = '0.0.0.0' Then
                GUICtrlSetData($Progress, 0)
                GUICtrlSetState($Button1, $GUI_ENABLE)
                Sleep(1000)
            Else
                $sCurr1 = ping($host1, 4000)
                $sCurr2 = ping($host2, 4000)
                If $sCurr1 = 0 Then
                    GUICtrlSetData($Progress, 0)
                    ToolTip('No signal, please wait!...', 850, 678)
                Else
                    ToolTip('')
                    GUICtrlSetData($Progress, $allping)
                    $allping = $sCurr1+$sCurr2
                EndIf
                If $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, "", "Please to the Internet.")
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, "", "Please fill Link's website in the box.")
                ContinueLoop
            Else
                ToolTip("Please wait!...", 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, "", "Please to the Internet.")
Else
    ShellExecute($url)
EndIf
EndFunc
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

  • Recently Browsing   0 members

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