Excelde Bilgisayarın MACAdresini Alma

Kodlar incelenince ne olduğu anlaşılıyor. 



Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim strComputer As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim myMACAddress As String
Dim s As Worksheet
Dim x As Integer


Set s = Sheets("logs")


x = s.Range("a1").End(xlDown).Row


'Set the computer.
strComputer = "."

'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'A select query is used to get a collection of network adapters that have the property IPEnabled equal to true.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

'Loop through all the collection of adapters and return the MAC address of the first adapter that has a non-empty IP.
For Each objItem In colItems
If Not IsNull(objItem.IPAddress) Then myMACAddress = objItem.MACAddress
Exit For
Next


If myMACAddress = "D4:AE:52:B7:A5:9B" Then
s.Range("a" & x + 1) = x
s.Range("b" & x + 1) = Now
s.Range("c" & x + 1) = "cüneyt"
ElseIf myMACAddress = "6C:F0:49:B3:D1:90" Then
s.Range("a" & x + 1) = x
s.Range("b" & x + 1) = Now
s.Range("c" & x + 1) = "karaca"
ElseIf myMACAddress = "78:2B:CB:CC:93:8F" Then
s.Range("a" & x + 1) = x
s.Range("b" & x + 1) = Now
s.Range("c" & x + 1) = "serdar"
Else
s.Range("a" & x + 1) = x
s.Range("b" & x + 1) = Now
s.Range("c" & x + 1) = myMACAddress
End If

ActiveWorkbook.Save

End Sub


Paylaşmayı unutmayın!
0 0 votes
Article Rating
Subscribe
Bildir
guest
0 Yorum
Inline Feedbacks
View all comments