我在网上看到使用excel来获取计算机的mac地址。有没有办法使用该方法来确保单个vba文件只能运行到非常特定的计算机,以避免非法分发文件。
我从宏guro得到的代码:他的代码将以消息框的形式显示mac地址。
Function GetMACAddress() As String
Dim sComputer As String
Dim oWMIService As Object
Dim cItems As Object
Dim oItem As Object
Dim myMacAddress As String
sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set cItems = oWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each oItem In cItems
If Not IsNull(oItem.IPAddress) Then myMacAddress = oItem.macAddress
Exit For
Next
'it will return mac address in format MM:MM:MM:SS:SS:SS
MsgBox myMacAddress
GetMACAddress = myMacAddress
End Function