Netzwerkkarten deactivieren und wieder activieren von allen betriebsystemen?

  • Hi :)
    Leute suche eine lösung die netzwerkkarten von jederman zu deactiviern und wieder zuactivieren egal was für beribssystem oder bit!
    habe in diversen foren durchsucht probiert und nicht hinbekomen!
    bei den meisten muss man ne id von netzwerkkarten(Devcon) eingeben !
    das geht ja bei mir nicht weill ich will das der script bei jedem funktioniert und jeder hat ne andere id bzw. Betriebssystem (32,64bit).
    das habe ich von einem anderen autoit forum!:

    Spoiler anzeigen
    [autoit]

    ;====================================================================================================================
    ; Name : _NicControl
    ; Description : Activate or deactivate a Network Interface Controler (NIC)
    ; Syntax : _NicControl($oLanConnection, [$iFlag, , [$iFullName]])
    ; Parameter(s) : $oLanConnection - The name of the Lan connection.
    ; If equal to 'All' then change state of all NIC.
    ; $iFlag - The state of the NIC (Default 1 for activate).
    ; $iFullName - Look for string $oLanConnection in NIC name (Default 1 for full name).
    ; Requirement(s) : Win32_NT OS
    ; Return value(s) : On Success - Return 1
    ; On Failure - Return 0 and @Extented is set.
    ; @Extented = 1 : Not Win32_NT OS
    ; @Extented = 2 : Network folder not find.
    ; @Extented = 3 : Lan connection not find.
    ; Author : Tlem <tlem at tuxolem dot net>
    ; http://www.autoitscript.fr/forum/viewtopic.php?f=21&t=1092
    ; Note(s) :
    ;
    ; To Do : Get individual errors for changing state of multiple NIC (Perhaps with array).
    ; ===================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    #RequireAdmin
    Global $strEnableVerb
    Global $strDisableVerb
    Global $strFolderName

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ===================================================================================================================
    ; ===================================================================================================================
    ; Exemple :
    ; $Res = _NICContol('all', 1, 0)
    ; MsgBox(0, "", "$Res=" & $Res & " @Error=" & @error & " @extented=" & @extended)
    ; ===================================================================================================================
    ; ===================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _NICContol($oLanConnection, $iFlag = 1, $iFullName = 1)
    ; Control OS type.
    If @OSTYPE <> "WIN32_NT" Then
    SetError(1, 1)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Langage selection.
    Select
    ; English (United States)
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang)
    $strEnableVerb = "En&able"
    $strDisableVerb = "Disa&ble"
    If @OSVersion = "WIN_2000" Then
    $strFolderName = "Network and Dial-up Connections" ; Windows 2000
    Else
    $strFolderName = "Network Connections"; Windows XP
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Français (France)
    Case StringInStr("040c,080c,0c0c,100c,140c,180c", @OSLang)
    $strEnableVerb = "&Activer"
    $strDisableVerb = "&Désactiver"
    If @OSVersion = "WIN_2000" Then
    $strFolderName = "Connexions réseau et accès à distance" ; Windows 2000
    Else
    $strFolderName = "Connexions réseau"; Windows XP
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Add here the correct Verbs for your Operating System Language
    EndSelect

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Vista/W2K8
    If @OSVersion <> "WIN_2000" And @OSVersion <> "WIN_XP" And @OSVersion <> "WIN_2003" Then
    $Res = _NICContolWin32New($oLanConnection, $iFlag, $iFullName)
    Else
    ; W2K/XP/W2K3
    $Res = _NICContolWin32($oLanConnection, $iFlag, $iFullName)
    EndIf

    SetError(@error, @extended)
    Return $Res

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_NICContol

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _NICContolWin32($oLanConnection, $iFlag = 1, $iFullName = 1)
    ; Inspired from :
    ; Original author : SvenP
    ; http://www.autoitscript.com/forum/index.ph…indpost&p=87000
    $ShellApp = ObjCreate("Shell.Application")
    $oControlPanel = $ShellApp.Namespace(3)

    [/autoit] [autoit][/autoit] [autoit]

    ; Find 'Network connections' control panel item
    $oNetConnections = ""
    For $FolderItem In $oControlPanel.Items
    If $FolderItem.Name = $strFolderName Then
    $oNetConnections = $FolderItem.GetFolder
    ExitLoop
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; If no 'Network connections' folder then return error.
    If Not IsObj($oNetConnections) Then
    SetError(1, 2)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Change all NIC state (Do not return extented errors).
    If StringLower($oLanConnection) = "all" Then
    For $FolderItem In $oNetConnections.Items
    _NICContolWin32($FolderItem.name, $iFlag)
    Next
    Return 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Change NIC state by partial name (Do not return extented errors).
    If $iFullName = 0 Then
    For $FolderItem In $oNetConnections.Items
    If StringInStr(StringLower($FolderItem.name), StringLower($oLanConnection)) Then
    _NICContolWin32($FolderItem, $iFlag)
    EndIf
    Next
    Return 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Find the collection of the network connection name.
    For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
    $oLanConnection = $FolderItem
    ExitLoop
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; If no network connection name then return error.
    If Not IsObj($oLanConnection) Then
    SetError(1, 3)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $oEnableVerb = ""
    $oDisableVerb = ""

    [/autoit] [autoit][/autoit] [autoit]

    ; Find the state of the network connection.
    For $Verb In $oLanConnection.Verbs
    If $Verb.Name = $strEnableVerb Then
    $oEnableVerb = $Verb
    $State = 0
    EndIf
    If $Verb.Name = $strDisableVerb Then
    $oDisableVerb = $Verb
    $State = 1
    EndIf
    Next

    If $iFlag = 3 Then Return $State

    [/autoit] [autoit][/autoit] [autoit]

    ; Enable NIC
    If $iFlag Then
    If IsObj($oEnableVerb) Then $oEnableVerb.DoIt
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Disable NIC
    If Not $iFlag Then
    If IsObj($oDisableVerb) Then $oDisableVerb.DoIt
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $begin = TimerInit()
    While 1
    $dif = Int(TimerDiff($begin) / 1000)
    If $dif > 10 Then ExitLoop
    ; Control the state of the NIC to exit before the end of waiting time.
    If $iFlag = 1 And _NICContolWin32($oLanConnection, 3) = 1 Then ExitLoop
    If $iFlag = 0 And _NICContolWin32($oLanConnection, 3) = 0 Then ExitLoop
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; Set the return value of the function.
    $Res = _NICContolWin32($oLanConnection, 3)
    If $iFlag = 1 And $Res = 0 Then
    Return 0
    ElseIf $iFlag = 0 And $Res = 1 Then
    Return 0
    Else
    Return 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_NICContolWin32

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _NICContolWin32New($oLanConnection, $iFlag = 1, $iFullName = 1)
    ; Inspired from :
    ; Original author : Danny35d
    ; http://www.autoitscript.com/forum/index.ph…ndpost&p=528862
    $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x30)
    If IsObj($colItems) Then
    $iModState = 0

    [/autoit] [autoit][/autoit] [autoit]


    ; Activate All NIC (Return just 1 if function end correctly).
    If StringLower($oLanConnection) = "all" Then
    For $objItem In $colItems
    If $objItem.NetConnectionID <> '' Then
    _NICContolWin32New($objItem.NetConnectionID, $iFlag)
    EndIf
    Next
    Return 1
    EndIf

    ; Change NIC state by partial name (Return just 1 if function end correctly or if no connection was find).
    If $iFullName = 0 Then
    For $objItem In $colItems
    If StringInStr(StringLower($objItem.NetConnectionID), StringLower($oLanConnection)) Then
    $iModState = 1
    $Res = _NICContolWin32New($objItem.NetConnectionID, $iFlag)
    EndIf
    Next
    ; If no connection find.
    If $iModState = 0 Then
    SetError(1,3)
    Return 0
    Else
    Return 1
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Change NIC state of $oLanConnection
    For $objItem In $colItems
    If $objItem.NetConnectionID = $oLanConnection Then
    ; Check State.
    If $iFlag = 3 Then
    If $objItem.NetEnabled = True Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    ; Change State.
    If $iFlag = 0 And $objItem.NetEnabled = True Then
    $objItem.Disable
    ElseIf $iFlag = 1 And $objItem.NetEnabled = False Then
    $objItem.Enable
    EndIf
    $iModState = 1
    EndIf
    ExitLoop
    EndIf
    Next
    ; If no connection then error.
    If $iModState = 0 Then
    SetError(1, 3)
    Return 0
    EndIf
    Else
    SetError(1, 2)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $iFlag = 3 Then
    While $iFlag <> _NICContolWin32New($oLanConnection, 3)
    Sleep(250)
    WEnd
    Else
    Sleep(1000)
    If $iFlag = 1 And _NICContolWin32New($oLanConnection, 3) = 1 Then
    Return 1
    ElseIf $iFlag = 0 And _NICContolWin32New($oLanConnection, 3) = 0 Then
    Return 1
    Else
    Return 0
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_NICContolWin32New

    [/autoit]


    download

    bin jeder hilfe dankbar! :thumbup:

    mfg
    FISO

    2 Mal editiert, zuletzt von FISO (20. April 2010 um 22:14)

  • Hallo FISO,

    für welche Anwendungsart braucht man denn so etwas. SpassVirus :?:

    mfg (Auto)Bert

    Für mac changer!

    Funktionen einfach zu übernehmen macht wenig Sinn.
    Man sollte schon einen Blick hineinwerfen.
    In der Funktion _NICContol()
    wird $strFolderName in Abhängigkeit zur Systemsprache gesetzt.
    Es wird aber nur EN und FR abgeprüft. Für dein System bleibt demzufolge
    die Variable einfach leer.

    Hast recht geb mein bestes das ganze zu lernen ist für mich als anfänger nicht leicht! ^^
    meinst du eine systemabfrage würde da helfen?!

    Einmal editiert, zuletzt von FISO (21. April 2010 um 21:36)