在XP或WIN2000中怎样用VB得到计算机的网卡号
<p>求救:</p><p>在XP或WIN2000中怎样用VB得到计算机的网卡号?以前我有一段代码在W98中好使,但在XP或Win2000中运行时,网卡号总是由0组成的,这是为什么?请高手赐教</p><p></p> 关注中,想在VBA中实现—— <p>Option Explicit<br/>Private Const NCBASTAT = &H33<br/>Private Const NCBNAMSZ = 16<br/>Private Const HEAP_ZERO_MEMORY = &H8<br/>Private Const HEAP_GENERATE_EXCEPTIONS = &H4<br/>Private Const NCBRESET = &H32</p><p>Private Type NCB<br/> ncb_command As Byte ''Integer<br/> ncb_retcode As Byte ''Integer<br/> ncb_lsn As Byte ''Integer<br/> ncb_num As Byte '' Integer<br/> ncb_buffer As Long ''String<br/> ncb_length As Integer<br/> ncb_callname As String * NCBNAMSZ<br/> ncb_name As String * NCBNAMSZ<br/> ncb_rto As Byte ''Integer<br/> ncb_sto As Byte '' Integer<br/> ncb_post As Long<br/> ncb_lana_num As Byte ''Integer<br/> ncb_cmd_cplt As Byte ''Integer<br/> ncb_reserve(9) As Byte '' Reserved, must be 0<br/> ncb_event As Long<br/>End Type</p><p>Private Type ADAPTER_STATUS<br/> adapter_address(5) As Byte ''As String * 6<br/> rev_major As Byte ''Integer<br/> reserved0 As Byte ''Integer<br/> adapter_type As Byte ''Integer<br/> rev_minor As Byte ''Integer<br/> duration As Integer<br/> frmr_recv As Integer<br/> frmr_xmit As Integer<br/> iframe_recv_err As Integer<br/> xmit_aborts As Integer<br/> xmit_success As Long<br/> recv_success As Long<br/> iframe_xmit_err As Integer<br/> recv_buff_unavail As Integer<br/> t1_timeouts As Integer<br/> ti_timeouts As Integer<br/> Reserved1 As Long<br/> free_ncbs As Integer<br/> max_cfg_ncbs As Integer<br/> max_ncbs As Integer<br/> xmit_buf_unavail As Integer<br/> max_dgram_size As Integer<br/> pending_sess As Integer<br/> max_cfg_sess As Integer<br/> max_sess As Integer<br/> max_sess_pkt_size As Integer<br/> name_count As Integer<br/>End Type</p><p>Private Type NAME_BUFFER<br/> name As String * NCBNAMSZ<br/> name_num As Integer<br/> name_flags As Integer<br/>End Type</p><p>Private Type ASTAT<br/> adapt As ADAPTER_STATUS<br/> NameBuff(30) As NAME_BUFFER<br/>End Type</p><p>Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte<br/>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)<br/>Private Declare Function GetProcessHeap Lib "kernel32" () As Long<br/>Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long<br/>Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long</p><p>Private Sub Command1_Click()</p><p></p><p> Dim myNcb As NCB<br/> Dim bRet As Byte<br/> myNcb.ncb_command = NCBRESET<br/> bRet = Netbios(myNcb)<br/> myNcb.ncb_command = NCBASTAT<br/> myNcb.ncb_lana_num = 0<br/> myNcb.ncb_callname = "* "<br/> Dim myASTAT As ASTAT, tempASTAT As ASTAT<br/> Dim pASTAT As Long<br/> myNcb.ncb_length = Len(myASTAT)<br/> Debug.Print Err.LastDllError<br/> pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, myNcb.ncb_length)<br/> If pASTAT = 0 Then<br/> Debug.Print "memory allcoation failed!"<br/> Exit Sub<br/> End If<br/> myNcb.ncb_buffer = pASTAT<br/> bRet = Netbios(myNcb)<br/> Debug.Print Err.LastDllError<br/> CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)<br/> 'MsgBox Hex(myASTAT.adapt.adapter_address(0)) & " " & Hex(myASTAT.adapt.adapter_address(1)) _<br/> & " " & Hex(myASTAT.adapt.adapter_address(2)) & " " _<br/> & Hex(myASTAT.adapt.adapter_address(3)) _<br/> & " " & Hex(myASTAT.adapt.adapter_address(4)) & " " _<br/> & Hex(myASTAT.adapt.adapter_address(5))<br/> ' HeapFree GetProcessHeap(), 0, pASTAT<br/> <br/> Form1.Text1.Text = (myASTAT.adapt.adapter_address(0)) & " " & Hex(myASTAT.adapt.adapter_address(1)) _<br/> & " " & Hex(myASTAT.adapt.adapter_address(2)) & " " _<br/> & Hex(myASTAT.adapt.adapter_address(3)) _<br/> & " " & Hex(myASTAT.adapt.adapter_address(4)) & " " _<br/> & Hex(myASTAT.adapt.adapter_address(5))<br/> Dim pangduan As String<br/> pangduan = "0 17 31 B5 AF C"<br/> 'If Form2.Text1(0).Text = pangduan Then<br/> ' Form2.Command1.Enabled = True<br/> 'Else<br/> ' MsgBox "对不起,您的网卡地址有误,请重新获取或检查网络配置"<br/> 'End If</p><p>End Sub<br/></p> <p>我试了以上代码,但显示的是"0 0 0 0 0 0",我的机子XP系统,请赐教.多谢</p>
页:
[1]