Netzwerkverbindungen auslesen und einzelne ändern

  • Hi,
    bei mir sitzt mal wieder ein Elefant auf dem Schlauch.
    Ich versuche vorhandene Netzwerkverbindungen auszulesen und würde diese gerne ändern können.
    Das Problem:

    • In der Registry stehen viel mehr Verbindungen, als bei mir vorhanden sind. Unter anderem auch alte, gelöschte.
    • In der Systemsteuerung bietet mir WindowInfo nichts an.

    Ich könnte zwar die Netzwerkadapter-Seite aufrufen lassen, kann damit aber nichts anfangen. Weder sind die Verbindungen als Fenster-Text verfügbar, noch gibt es Control-IDs.

    Ziel ist, aus den vorhandenen Verbindungen eine auswählen zu können und diese dann gezielt zu ändern.

    Jetzt stellt sich mir nur noch die Frage, wie ich das machen soll.
    Hoffentlich könnt ihr mir helfen. Es kann doch nicht sein, dass AutoIt an der Systemsteuerung scheitert.

    PS: Mein System ist Windows 7. Das Prog sollte später aber auch noch unter XP laufen können(optional).

  • Ja, das ist schon nicht schlecht, danke dafür.
    Damit erhalte ich immerhin schon mal die Namen.

    Deine Scripte zur Änderung sind auch nicht schlecht, allerdings sollte ich bei meinen Angaben evtl. konkreter sein.
    In den Eigenschaften der einzelnen Adapter kann man ja auswählen, was dieser unterstützten soll(IPV6, IPV4, ...).
    Das geht dort über Checkboxen.
    Diese Auswahl würde ich gerne irgendwie automatisieren.
    Nur solange ich nicht in den Eigenschaften-Dialog des jeweiligen Adapters komme, wird da nicht viel möglich sein.

  • Da würde ich gleich bei der WMI bleiben
    Siehe: http://msdn.microsoft.com/en-us/library/…7(v=VS.85).aspx
    auch Interessant:
    http://msdn.microsoft.com/en-us/library/…6(v=VS.85).aspx
    Hier ein Beispiel ;)

    Adapter deaktivieren
    [autoit]

    Local Const $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20

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

    ; #FUNCTION# ======================================================================================
    ; Name .............: _WinWMI_NetworkAdapter_SetState()
    ; Description ......: Enables/Disables an Networkadapter
    ; Syntax ...........: _WinWMI_NetworkAdapter_SetState($sAdapterName, $sSetState, $sComputer)
    ; Parameters .......: Const $sAdapterName - Adaptername
    ; Const $sSetState - Status
    ; Const $sComputer - [optional] Target Computer (default:"127.0.0.1")
    ; Return values ....: Success - 1
    ; Failure - 0 Sets @error to:
    ; |-1 Connection failed
    ; |-2 WMI Class not found/no access
    ; |-3 Enable/Disable failed
    ; Author ...........: Mahagon
    ; Link .............: http://msdn.microsoft.com/en-us/library/…6(v=VS.85).aspx
    ; =================================================================================================

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

    Func _WinWMI_NetworkAdapter_SetState(Const $sAdapterName, Const $sSetState, Const $sComputer = "127.0.0.1")
    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\CIMV2")
    If IsObj($oWMI) = 0 Then Return SetError(-1, @error, 0)
    $oList = $oWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & $sAdapterName & "'", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($oList) = 0 Or Not IsAdmin() Then Return SetError(-2, @error, 0)
    For $oItem In $oList
    Local $errorlevel = 1
    If $sSetState = "Disable" Then $errorlevel = $oItem.Disable()
    If $sSetState = "Enable" Then $errorlevel = $oItem.Enable()
    If $errorlevel <> 0 Then Return SetError(-3, @error, 0)
    Next
    Return 1
    EndFunc ;==>_WinWMI_NetworkAdapter_SetState

    [/autoit]
    Hier noch Allgemeines zum Auslesen von Informationen ;)
    [autoit]

    ; #FUNCTION# ======================================================================================
    ; Name .............: _WinWMI_UserAccount_GetInformation()
    ; Description ......: Returns requested Userinformation in a 2D Array
    ; Syntax ...........: _WinWMI_UserAccount_GetInformation(Const[ $sFields = "Name",Const[ $sUser = "%",Const[ $sComputer = "127.0.0.1"]]])
    ; Parameters .......: Const $sFields - [optional] Userinformation seperated by comma (default:"Name")
    ; $sUser - [optional] Users seperated by comma (default:"%")
    ; Const $sComputer - [optional] Target Computer (default:"127.0.0.1")
    ; Return values ....: Success - requested Userinformation in a 2D Array
    ; Failure - 0 Sets @error to:
    ; |-1 Connection failed
    ; |-2 WMI Class not found/no access
    ; |-3 No matches found
    ; Author ...........: Mahagon
    ; Link .............: http://msdn.microsoft.com/en-us/library/…7(v=VS.85).aspx
    ; Link (German).....: http://www.scriptinternals.de/new/ger/suppor…UserAccount.htm
    ; Au3.api extension.: _WinWMI_UserAccount_GetInformation( [ "Fieldnames" [, "Username" [, "Target Computer"]]] ) Returns requested Userinformation in a 2D Array ( Requires: #include <WinWMI_UserAccount.au3> )
    ; =================================================================================================

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

    Func _WinWMI_UserAccount_GetInformation(Const $sFields = "Name", $sUser = "%", Const $sComputer = "127.0.0.1")
    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\CIMV2")
    If IsObj($oWMI) = 0 Then Return SetError(-1, @error, 0)
    $sUser = StringReplace($sUser, ",", "' Or Name LIKE '")
    $oList = $oWMI.ExecQuery("SELECT " & $sFields & " FROM Win32_UserAccount WHERE Name LIKE '" & $sUser & "'", "WQL")
    If IsObj($oList) = 0 Then Return SetError(-2, @error, 0)
    $aFields = StringSplit($sFields, ",", 2)
    If $oList.Count = 0 Then Return SetError(-3, @error, 0)
    Local $aReturn[$oList.Count][UBound($aFields)]
    $iCount = 0
    For $oItem In $oList
    With $oItem
    For $iFields = 0 To UBound($aFields) - 1
    Switch $aFields[$iFields]
    Case "AccountType"
    $aReturn[$iCount][$iFields] = .AccountType
    Case "Caption"
    $aReturn[$iCount][$iFields] = .Caption
    Case "Description"
    $aReturn[$iCount][$iFields] = .Description
    Case "Disabled"
    $aReturn[$iCount][$iFields] = .Disabled
    Case "Domain"
    $aReturn[$iCount][$iFields] = .Domain
    Case "FullName"
    $aReturn[$iCount][$iFields] = .FullName
    Case "InstallDate"
    $aReturn[$iCount][$iFields] = .InstallDate
    Case "LocalAccount"
    $aReturn[$iCount][$iFields] = .LocalAccount
    Case "Lockout"
    $aReturn[$iCount][$iFields] = .Lockout
    Case "Name"
    $aReturn[$iCount][$iFields] = .Name
    Case "PasswordChangeable"
    $aReturn[$iCount][$iFields] = .PasswordChangeable
    Case "PasswordExpires"
    $aReturn[$iCount][$iFields] = .PasswordExpires
    Case "PasswordRequired"
    $aReturn[$iCount][$iFields] = .PasswordRequired
    Case "SID"
    $aReturn[$iCount][$iFields] = .SID
    Case "SIDType"
    $aReturn[$iCount][$iFields] = .SIDType
    Case "Status"
    $aReturn[$iCount][$iFields] = .Status
    EndSwitch
    Next
    EndWith
    $iCount += 1
    Next
    Return $aReturn
    EndFunc ;==>_WinWMI_UserAccount_GetInformation

    [/autoit]

    21 is only half the truth.

    2 Mal editiert, zuletzt von Mahagon (27. September 2010 um 20:19)