Jump to content
Sign in to follow this  
jp10558

Getting Windows name of Local Area Connection

Recommended Posts

jp10558

I'm working on reimplementing and extending a setup script I have for recently imaged PCs. One issue for the commandline setup of our static IPs is we need to pass netsh the connection name. For reasons that are unknown, occasionally Windows will call Local Area Connection or Local Area Connection 2 etc... Is there any way in AutoIT to pull what the current wired connection (vs Wireless say) name from Windows so I can build the correct netsh command?

Share this post


Link to post
Share on other sites
Legacy99

You could do a WMI query for the Description which should alway be the same (depending on your driver) and get the NetConnectionID that way, pump it to a variable and use it in your netsh command

It's tricky any way you do it because typically you have to loop through all the adapters that are on the system to find the right one.

Taken from Scriptomatic as an example

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "NetConnectionID: " & $objItem.NetConnectionID & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapter" )
Endif


Func WMIDateStringToDate($dtmDate)
Edited by Legacy99

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.