MAC address

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
lcrltd
Junior Coder
Posts: 35
Joined: Thu Nov 16, 2006 8:23 am

MAC address

Post by lcrltd » Thu Jun 12, 2008 2:51 pm

Is there a way to get the MAC address of a network card in MS ? I would like to simply get it and reference it in a txt file?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 12, 2008 3:05 pm

The following returns all MAC addresses and associated IP addresses. It returns all for the local machine.

Code: Select all

VBSTART

Function GetMacAddresses
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
  Result = ""
  For Each objItem in colItems
      Result = Result & objItem.MACAddress & ":"
      For Each strAddress in objItem.IPAddress
          Result = Result & strAddress & ","
      Next
	  Result = Result & vbCRLF
  Next
  GetMacAddresses = Result
End Function

VBEND

VBEval>GetMacAddresses,macAddresses
MessageModal>macAddresses
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts