Jump to content

auto stop LAN


Guest trektaiwan
 Share

Recommended Posts

In your case, the most effective way would be to pull the plug!  :whistle:

LOL! :dance:

@trektaiwan

Hmmm... What OS? If this is Win2K/XP/2003, you could disable the adapter. I'm sure it could be done with a DLL call, but I don't know which DLL or function. Search the MSDN. Otherwise, you could bring up the network connections control panel, right-click the appropriate one, and hit disable.

My UDFs: ExitCodes

Link to comment
Share on other sites

Guest trektaiwan

LOL! :whistle:

@trektaiwan

Hmmm... What OS?  If this is Win2K/XP/2003, you could disable the adapter.  I'm sure it could be done with a DLL call, but I don't know which DLL or function.  Search the MSDN.  Otherwise, you could bring up the network connections control panel, right-click the appropriate one, and hit disable.

<{POST_SNAPBACK}>

maybe ok, but need to get mouse position and right click ...

my problem is how to auto stop and auto start LAN at sometime ...

Link to comment
Share on other sites

I believe that

netsh interface set interface "Local Area Connection" disable

would do it, else try admin = disable at the end

Source:  netsh help documentation

<{POST_SNAPBACK}>

I think that only works for WAN connections, not LAN conections.

I've looked into this before, and I've never been able to find a way to enable and disable NICs programatically.

Link to comment
Share on other sites

Here you go:

This method uses COM so it needs latest beta to work.

AutoItSetOption("MustDeclareVars", 1)

Dim $sEnableVerb = "En&able" 
Dim $sDisableVerb = "Disa&ble" 

; Usage example
_ToggleConnection("Local Area Connection", $sDisableVerb)

Func _ToggleConnection($sConnectionName, $sVerb)
    Local $oShell
    Local $oControlPanel
    Local $oFolderItem
    Local $oNetConnections
    Local $oConnectionItem
    Local $oLanConnection
    Local $oVerbItem
    Local $oVerb
    
    $oShell = ObjCreate("Shell.Application") 
    $oControlPanel = $oShell.Namespace(3)
    For $oFolderItem In $oControlPanel.Items 
    ; ConsoleWrite($oFolderItem.Name & @LF)
    ; Look up network connection folder name in control panel
        If $oFolderItem.Name = "Network Connections" Then 
            $oNetConnections = $oFolderItem.GetFolder
            ExitLoop
        EndIf
    Next     
    If Not IsObj($oNetConnections) Then Return 0
    For $oConnectionItem In $oNetConnections.Items 
    ; ConsoleWrite($oConnectionItem.Name & @LF)
        If $oConnectionItem.Name  = $sConnectionName Then 
            $oLanConnection = $oConnectionItem
            ExitLoop
        EndIf
    Next
    If Not IsObj($oLanConnection) Then Return 0
    For $oVerbItem In $oLanConnection.Verbs 
    ; ConsoleWrite($oVerbItem.Name & @LF)
        If $oVerbItem.Name = $sVerb Then 
            $oVerb = $oVerbItem
            ExitLoop
        EndIf
    Next
    If Not IsObj($oVerb) Then Return 0
    $oVerb.DoIt()
; Needs delay to allow action to complete
    Sleep(1000)
    
    Return 1
EndFunc
Edited by SumTingWong
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...