write at exceltoexplore@gmail.com : Report Automation|Dashboard in Excel| Provide Excel consulting through macro (VBA) automation |Financial Modeling | Ethical Hacking

Monday, 13 June 2011

Determine physical address (MAC Address) of PC

Every network interface has a MAC address (Media Access Controller) also known as the physical address. This is the actual hardware address that the lowest level of the network uses to communicate.
The MAC address is used to assign the TCP/IP address by means of DHCP (Dynamic Host Configuration Protcol). For that reason, we need the MAC address of a machine so that it can be properly, and easily configured for the network.
You can enter ipconfig/all in cmd prompt and find Physical address i.e MAC address
vb code Try :
Sub MAC()
Dim strCom As String
Dim objWMIService As Object
Dim colAdapters As Object
Dim objAdapter As Object
strCom = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strCom & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter In colAdapters
MsgBox "Physical address : " & objAdapter.MACAddress
Next objAdapter
End Sub

2 comments:

  1. how can I convert this to a string variable- CTYPE does not work for me
    errolw@xpertus.com

    ReplyDelete
  2. I made workaround over a dozen of codes and a bunch of modules about this subject. This code is the only only only one working flawlessly. Thanks!!!

    ReplyDelete