WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

List Active Network Adapters

 Keywords: List Active Network Adapters 

Sample Code: List Active Network Adapters

Here is some code that retrieves a list of active network adapters using WMI (Windows Management Instrumentation). It retrieves the same list you see in the Device Manager under network adapters:



; Specify "" for local computer or a computer name (i.e. "COMPUTER01")
ComputerName = ""
User = ""
Password = ""

; Get handle to WMI locator
objLocator = ObjectCreate("WbemScripting.SWbemLocator")

; Connect to local or remote machine
objService = objLocator.ConnectServer(ComputerName,"root/cimv2",User,Password)

; Set security level
objSecurity = objService.Security_
objSecurity.ImpersonationLevel = 3

; Execute WMI query on the WMI Win32_NetworkAdapterConfiguration class
colAdapters = objService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

; Get handle to object collection
hEnum = ObjectCollectionOpen(colAdapters)
While 1
   ; get adapter object handle
   objAdapter = ObjectCollectionNext(hEnum)

   ; Check if finished enumerating
   If objAdapter == 0 Then Break

   Message("Network Adapter", objAdapter.Description)

   ; Get IP address of adapter
   objIPAddress = objAdapter.IPAddress
   cnt = ArrInfo(objIPAddress, 1)
   For i = 0 To cnt-1
      Message("IP address=",objAdapter.IPAddress(i))
   Next

  ; Close object handle
  colAdapters = 0
EndWhile

; Close handle to object collection
ObjectCollectionClose(hEnum)

; Explicitly close object handles
objSecurity = 0
objService = 0
objLocator = 0

Exit

What is WMI?

Windows® Management Instrumentation (WMI) is a component of the Microsoft® Windows® operating system and is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components. You can use WMI to automate administrative tasks in an enterprise environment.

For more on WinBatch and WMI:

WMI Scripter: Tool to help users to generate and run scripts that use WMI. Tech Support Article ID: W16283


Article ID:   W17501
File Created: 2014:07:18:09:11:48
Last Updated: 2014:07:18:09:11:48