2013-05-10 147 views
3

我正在尝试为我正在编写的Excel(Windows)应用程序提供一些基本级别的保护。我正在考虑使用机器的mac地址生成许可证文件。我的问题是:如何使用VBScript获取Mac地址?使用VBScript获取Mac地址

回答

5
dim WMI: set WMI = GetObject("winmgmts:\\.\root\cimv2") 
dim Nads: set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true") 
dim nad 
for each Nad in Nads 
    if not isnull(Nad.MACAddress) then Wscript.Echo Nad.description, Nad.MACAddress 
next 

但是MAC可能是一个糟糕的选择; What's a good way to uniquely identify a computer?

这将返回所有物理适配器,但对于我,我也看到我的Cisco Systems VPN Adapter for 64-bit Windows,我不会形容为物理。

+0

感谢您的回答。它工作正常。关于你对这是一个糟糕的选择的评论,我同意。但我们只需要一种简单而快速的方法来阻止对工具的不当使用。由于只发布了它的几个副本,我们认为这足够了(现在)。 – carlossierra 2013-05-10 16:49:06

+0

@Alex,但如何获得只有“活动”网络的mac地址? – 2014-04-30 10:08:33

+0

希望这还不算太迟@SahilMittal,可以通过检查[Win32_NetworkAdapter from MSDN](https://msdn.microsoft.com/en-us/library/aa394216(v = vs。 85).aspx),查找** NetConnectionStatus = 2 ** + **速度不为零并且> 0 **,如果有线,无线连接,移动网络连接,您将不得不根据** AdapterType * *。 – PatricK 2017-04-18 23:28:49