写了一个收集IP\HOSTNAME\MAC的程序,但是在运行的时候提示:无效外部过程,请问是什么原因呢??Private Declare Function netbios Lib "netapi32.dll" (pncb As NCB) As Byte
Private Declare Function heapalloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function heapfree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As LongPrivate Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reservr(9) As Byte
ncb_event As Long
End Type udtNCB.ncb_command = NCBRESET
bytResponse = netbios(udtNCB)
udtNCB.ncb_command = NCBASTAT
udtNCB.ncb_lana_num = lanaNumber
udtNCB.ncb_callname = "*"
udtNCB.ncb_length = Len(udtastat)
lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
strout = ""
If lngASTAT Then
udtNCB.ncb_buffer = lngASTAT
byResponse = netbios(udtNCB)
CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
With udtastat.adapt
strout = Right$("00" & Hex$(.adapter_address(0)), 2)
For x = 1 To 5
strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
Next x
End With
heapfree GetProcessHeap(), 0, lngASTAT
End If
ethernetaddress = stroutPrivate Sub Command1_Click() Text1.Text = Winsock1.LocalIP
Text2.Text = Winsock1.LocalHostName
Text3.Text = ethernetaddress()
Winsock1.Close
End Sub
Private Declare Function heapalloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function heapfree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As LongPrivate Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reservr(9) As Byte
ncb_event As Long
End Type udtNCB.ncb_command = NCBRESET
bytResponse = netbios(udtNCB)
udtNCB.ncb_command = NCBASTAT
udtNCB.ncb_lana_num = lanaNumber
udtNCB.ncb_callname = "*"
udtNCB.ncb_length = Len(udtastat)
lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
strout = ""
If lngASTAT Then
udtNCB.ncb_buffer = lngASTAT
byResponse = netbios(udtNCB)
CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
With udtastat.adapt
strout = Right$("00" & Hex$(.adapter_address(0)), 2)
For x = 1 To 5
strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
Next x
End With
heapfree GetProcessHeap(), 0, lngASTAT
End If
ethernetaddress = stroutPrivate Sub Command1_Click() Text1.Text = Winsock1.LocalIP
Text2.Text = Winsock1.LocalHostName
Text3.Text = ethernetaddress()
Winsock1.Close
End Sub
bytResponse = netbios(udtNCB)
udtNCB.ncb_command = NCBASTAT
udtNCB.ncb_lana_num = lanaNumber
udtNCB.ncb_callname = "*"
udtNCB.ncb_length = Len(udtastat)
lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
strout = ""
If lngASTAT Then
udtNCB.ncb_buffer = lngASTAT
byResponse = netbios(udtNCB)
CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
With udtastat.adapt
strout = Right$("00" & Hex$(.adapter_address(0)), 2)
For x = 1 To 5
strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
Next x
End With
heapfree GetProcessHeap(), 0, lngASTAT
End If
ethernetaddress = strout
请问是由于什么原因呢??
Const NCBNAMSZ = 16
Const NCBRESET = &H32
Const HEAP_ZERO_MEMORY = &H8
Const HEAP_GENERATE_EXCEPTIONS = &H4
'1F的要放在这个事件里面Private Sub ethernetaddress()
udtNCB.ncb_command = NCBRESET
bytResponse = netbios(udtNCB)
udtNCB.ncb_command = NCBASTAT
udtNCB.ncb_lana_num = lanaNumber
udtNCB.ncb_callname = "*"
udtNCB.ncb_length = Len(udtastat)
lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
strout = ""
If lngASTAT Then
udtNCB.ncb_buffer = lngASTAT
byResponse = netbios(udtNCB)
CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
With udtastat.adapt
strout = Right$("00" & Hex$(.adapter_address(0)), 2)
For x = 1 To 5
strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
Next x
End With
heapfree GetProcessHeap(), 0, lngASTAT
End If
ethernetaddress = strout
End Sub
MsgBox "网卡MAC地址:" & Replace(MACAddress, ":", "-")
MsgBox "IP地址:" & Winsock1.LocalIP
MsgBox "主机名:" & Winsock1.LocalHostName '"机器名:" & Environ("computername")
MsgBox "用户名:" & Environ("username")
End SubPrivate Function MACAddress() As String
Set objs = GetObject("winmgmts:").ExecQuery("SELECT MACAddress " & "FROM Win32_NetworkAdapter " & "WHERE " & "((MACAddress Is Not NULL) " & "AND (Manufacturer <> " & "'Microsoft'))")
For Each obj In objs
MACAddress = obj.MACAddress
Exit For
Next obj
End Function
谢谢大哥您了,我现在只是在学习当中,初学VB,对VB的函数不了解。再次表示感谢~~!!