Jump to content

Getting Windows name of Local Area Connection


jp10558
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
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...