📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1800
TabIndex = 0
Top = 1320
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Function EthernetAddress() As String '使用WMI取网卡号,win2000和XP下用
On Error GoTo ErrorHandle
Dim objs, obj
Set objs = GetObject("winmgmts:").ExecQuery("SELECT MACAddress " & _
"FROM Win32_NetworkAdapter WHERE " & _
"((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))")
For Each obj In objs '有多个网卡,只取一个
EthernetAddress = obj.MACAddress
Exit For
Next
'取回来的格式为 00:00:00:00:00,去掉中间的:
EthernetAddress = Replace(EthernetAddress, ":", "-")
Exit Function
ErrorHandle:
' MsgBox "取网卡号错误,系统不能正常使用,请检查您的电脑硬件设备!" & Chr(13) & "请查看“服务”中WMI服务项是否有打开!", vbCritical, "帮助信息"
End Function
Private Sub Command1_Click()
MsgBox EthernetAddress
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -