Wie rufe ich die Methode RenewDHCPLeaseAll auf?

  • Hallo Zusammen,

    mit ObjGet etc. habe ich so gut wie keine Erfahrung und die Suchfunktion hilft mir auch nicht weiter. Dennoch habe ich es erfolgreich geschafft, durch Spicken in einem anderen Script, alle meine Netzwerkkarten in einem Rutsch mit folgendem Script auf DHCP umzustellen.

    Spoiler anzeigen
    [autoit]


    ; Alle Karten auf DHCP umstellen
    Func SetDHCPonAllCards()

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

    $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    ; Local $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration") ; Nimmt dann alle Adapter -> nicht gut!
    $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

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

    For $objNetCard In $collection

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

    ; --- enable DHCP ---
    $ret1 = $objNetCard.EnableDHCP()

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

    ; Error-Handling
    If $ret1 > 1 Then
    MsgBox(16, 'DHCP Set Error on ' & $objNetCard.macaddress, 'There was an unknown error setting DHCP')
    ElseIf $ret1 = 1 Then
    MsgBox(48, 'DHCP Set on ' & $objNetCard.macaddress, 'DHCP was set on the adapter. Please reboot for all changes to take affect')
    Else
    ;no error
    MsgBox(0, 'DHCP Set on ' & $objNetCard.macaddress, 'was succesful')
    EndIf
    Next
    EndFunc ;==>SetDHCPonAllCards

    [/autoit]

    Jetzt möchte ich noch ne Funktion schreiben, die alle DHCP-Leases erneuert. Dazu gibt es die Methode "RenewDHCPLeaseAll".

    Nur wie muß die ExecQuery aussehen, damit ich die Methode RenewDHCPLeaseAll erfolgreich absetzen kann?

    Ich hab es in der Schleife probiert, oder auch einzeln, aber ich bekomme immer einen Fehler. :( Wahrscheinlich muß die ganze Query anders ausschauen. Nur wie? ?(

    Hier der Links zu RenewDHCPLeaseAll Method of the Win32_NetworkAdapterConfiguration Class

    Besten Dank
    R@iner

  • du könntest ipconfig dazu benutzen.
    Batchbefehl:
    ipconfig /release


    oder versuchs mal damit:
    $result=DllCall("Cimwin32.dll","uint","RenewDHCPLeaseAll")

  • Hallo Bitboy,

    dank Dir für Deine Antwort. Ich hab jetzt eine Lösung gefunden, was aberimmer noch nicht meine Ursprungsfrage beantwortet.

    Spoiler anzeigen
    [autoit]


    ; DHCP auf allen (DHCP-)Karten erneuern
    Func RenewDHCP()

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

    $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    ; Local $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration") ; Nimmt dann alle Adapter -> nicht gut!
    $collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

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

    For $objNetCard In $collection

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

    ; Nur, wenn DHCP aktiv ist
    If $objNetCard.DHCPEnabled <> 0 Then

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

    ; --- Release DHCP ---
    $ret1 = $objNetCard.ReleaseDHCPLease()

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

    ; Error-Handling
    If $ret1 > 1 Then
    MsgBox(16, 'DHCP Release Error on ' & $objNetCard.macaddress, 'There was an unknown error setting DHCP')
    ElseIf $ret1 = 1 Then
    MsgBox(48, 'DHCP Release on ' & $objNetCard.macaddress, 'DHCP was set on the adapter. Please reboot for all changes to take affect')
    Else
    ;no error
    MsgBox(0, 'DHCP Release on ' & $objNetCard.macaddress, 'was succesful')
    EndIf

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

    ; --- Renew DHCP ---
    $ret1 = $objNetCard.RenewDHCPLease()

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

    ; Error-Handling
    If $ret1 > 1 Then
    MsgBox(16, 'DHCP Renew Error on ' & $objNetCard.macaddress, 'There was an unknown error setting DHCP')
    ElseIf $ret1 = 1 Then
    MsgBox(48, 'DHCP Renew on ' & $objNetCard.macaddress, 'DHCP was set on the adapter. Please reboot for all changes to take affect')
    Else
    ;no error
    MsgBox(0, 'DHCP Renew on ' & $objNetCard.macaddress, 'was succesful')
    EndIf

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

    EndIf
    Next
    EndFunc ;==>SetDHCPonAllCards

    [/autoit]


    Happy computing!
    R@iner