Sign in to follow this  
Followers 0
sumit

code to select dynamic ip settings in Local area connection

5 posts in this topic

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

Any suggestion would be appreciated.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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 ?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#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

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  
Followers 0