Jump to content

code to select dynamic ip settings in Local area connection


sumit
 Share

Recommended Posts

Can someone suggest how i can select dynamic ip settings and dynamic dns settings through code.

Any suggestion would be appreciated.

netsh?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Run('netsh interface ip set address "Local Area Connection" dhcp', "", @SW_HIDE)
Thanks a lot

Any suggestions what to do if the interface name is not Local Area Connection but something else .... is there a general script that would set dynamic ip in all possible interfaces irrespective of their names ?

Link to comment
Share on other sites

#include <array.au3>;Just to show the output you can remove this include

$myAdapters = _GetNICs()

If Not @error then 
    _ArrayDisplay($myAdapters);Just to show the output you can remove this line

    For $i = 1 to Ubound($myAdapters) -1
        Run('netsh interface ip set address "' & $myAdapters[$i] & '" dhcp', "", @SW_HIDE)
    Next
EndIf


Func _GetNICs()
    $colItems = ""
    $strComputer = "localhost"
    $Output=""
    Local $aAdapters[1] 
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID <> NULL and NetConnectionStatus <> '0'", "WQL")

    If IsObj($colItems) then
        For $objItem In $colItems
          $Output &=  $objItem.NetConnectionID & @CRLF
        Next
      If StringRight($Output,2) = @crlf then $Output = StringTrimRight($Output,2)
      $aAdapters = StringSplit($Output,@crlf,1)
    Else
      SetError(1)
    Endif
    SetError(0)
    Return $aAdapters
EndFunc

Edited by ChrisL
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...