Jump to content
Sign in to follow this  
Patron

Disable/Enable Local Area Connection Win7

Recommended Posts

Patron

how can i Disable/Enable Local Area Connection with win7?

Can anyone help me? :mellow:

this script works on win xp:

Area()
Func Area()
$nameLanConnection = "LAN-Verbindung"; Name des Adapters
$oLanConnection = ""

if @OSType<>"WIN32_NT" then
    Msgbox(0,"","Dieses Script benötigt Windows 2000 oder höher")
    exit
endif

Select
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang)    ; English (United States)
        $strEnableVerb  = "En&able"
        $strDisableVerb = "Disa&ble"
        if @OSVersion="WIN_2000" then
            $strFolderName = "Network and Dial-up Connections"
        else
            $strFolderName = "Network Connections" ; Windows XP
        endif

    Case StringInStr("0407", @OSLang); Deutsch
        $strEnableVerb  = "&Aktivieren"
        $strDisableVerb = "&Deaktivieren"
        if @OSVersion="WIN_2000" then
            $strFolderName = "Netzwerk- und DFÜ-Verbindungen"
        else
            $strFolderName = "Netzwerkverbindungen" ; Windows XP

        endif

EndSelect


;Virtueller Ordner (Wert 3) enthält die Systemsteuerung
Const $ssfCONTROLS = 3

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Finde 'Netzververbindungen' unter den Systemsteuerungen
$oNetConnections=""
For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $strFolderName then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next
If not IsObj($oNetConnections) Then
    Msgbox(0,"Fehler","Die Steuerung " & $strFolderName & " kann nicht gefunden werden."
    Exit
EndIf

; Finde die gesuchte LAN-Verbindung
For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($nameLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next
If not IsObj($oLanConnection) Then
    Msgbox(0,"Fehler","Die Verbindung " & $nameLanConnection & " kann nicht gefunden werden.")

EndIf

$bEnable = true
$oEnableVerb = ""
$oDisableVerb = ""

For $Verb In $oLanConnection.Verbs
    If $Verb.Name = $strEnableVerb Then
        $oEnableVerb = $Verb
        $bEnable = false
    EndIf
    If $Verb.Name = $strDisableVerb Then
        $oDisableVerb = $Verb
    EndIf
Next

If $bEnable then  ;<-----If
    ; deaktivieren
    $oDisableVerb.DoIt

else
    ; aktivieren
 $oEnableVerb.DoIt

    TrayTip("",$nameLanConnection & "LAN-Verbindung wurde aktiviert !",3)
    Sleep(3000)
Endif
$bEnable = true
$oEnableVerb = ""
$oDisableVerb = ""

For $Verb In $oLanConnection.Verbs
    If $Verb.Name = $strEnableVerb Then
        $oEnableVerb = $Verb
        $bEnable = false
    EndIf
    If $Verb.Name = $strDisableVerb Then
        $oDisableVerb = $Verb
    EndIf
Next

If $bEnable   then
    ; deaktivieren
   $oDisableVerb.DoIt
else
    ; aktivieren
    $oEnableVerb.DoIt

    TrayTip("",$nameLanConnection & "LAN-Verbindung wurde aktiviert !",3)
    Sleep(3000)
Endif

;-------------------------------------------------------------W-LAN--------------------------------------------------------------------------------
$nameLanConnection = "Drahtlose Netzwerkverbindung"; Name des Adapters
$oLanConnection = ""

; Finde die gesuchte LAN-Verbindung
For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($nameLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next
If not IsObj($oLanConnection) Then
    Msgbox(0,"Fehler","Die Verbindung " & $nameLanConnection & " kann nicht gefunden werden.")

EndIf
$bEnable = true
$oEnableVerb = ""
$oDisableVerb = ""

For $Verb In $oLanConnection.Verbs
    If $Verb.Name = $strEnableVerb Then
        $oEnableVerb = $Verb
        $bEnable = false
    EndIf
    If $Verb.Name = $strDisableVerb Then
        $oDisableVerb = $Verb
    EndIf
Next

If $bEnable then
    ; deaktivieren
    $oDisableVerb.DoIt
else
    ; aktivieren
    $oEnableVerb.DoIt
    TrayTip("",$nameLanConnection & "Drahtlose Netzwerkverbindung wurde aktiviert !",3)
Endif
Sleep(3000)
$bEnable = true
$oEnableVerb = ""
$oDisableVerb = ""

For $Verb In $oLanConnection.Verbs
    If $Verb.Name = $strEnableVerb Then
        $oEnableVerb = $Verb
        $bEnable = false
    EndIf
    If $Verb.Name = $strDisableVerb Then
        $oDisableVerb = $Verb
    EndIf
Next

If $bEnable then
    ; deaktivieren
    $oDisableVerb.DoIt
else
    ; aktivieren
    $oEnableVerb.DoIt
    TrayTip("",$nameLanConnection & "Drahtlose Netzwerkverbindung wurde aktiviert !",3)
Endif

Sleep(3000)
EndFunc

Share this post


Link to post
Share on other sites
Igzter

For windows 7 or Vista the easiest way is to use WMI (Win32_NetworkAdapter) and the disable method on the selected adapter.

Edit: http://msdn.microsoft.com/en-us/library/Aa394595 (here you go)

Edited by Igzter

Share this post


Link to post
Share on other sites
Igzter

wow thank you for the infomation! :mellow:

Thought I help you out a bit more - below you find soem sample code to list all physical adapters in the system and list their names (iWMILib is my own WMI library so you have to write your own connect and moniker code to execute or download the lib).

#NoTrayIcon
#include <iWMILib.au3>

_iWMI_Initialize()

$iConnection = _iWMI_Connect("localhost")
if @error Then
        ConsoleWrite("Error!" & @CRLF )
EndIf
$cObjects = _iWMI_ExecQueryRaw( $iConnection, 'Select * from Win32_NetworkAdapter Where PhysicalAdapter=True', False )
if @error Then
        ConsoleWrite("Error!" & @CRLF )
EndIf

For $oObject In $cObjects
        ConsoleWrite( $oObject.Name & @CRLF )
        ; oObject.Disable                           ; This will disable the adapter.
Next

Share this post


Link to post
Share on other sites
Patron

Thank you!

I will Test it now! :mellow:

Share this post


Link to post
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
Sign in to follow this  

×