wang_qiang 发表于 2007-8-2 21:13:00

在XP或WIN2000中怎样用VB得到计算机的网卡号

<p>求救:</p><p>在XP或WIN2000中怎样用VB得到计算机的网卡号?以前我有一段代码在W98中好使,但在XP或Win2000中运行时,网卡号总是由0组成的,这是为什么?请高手赐教</p><p></p>

idoo 发表于 2007-8-8 12:44:00

关注中,想在VBA中实现——

ngeqt521 发表于 2007-8-24 12:36:00

<p>Option Explicit<br/>Private Const NCBASTAT = &amp;H33<br/>Private Const NCBNAMSZ = 16<br/>Private Const HEAP_ZERO_MEMORY = &amp;H8<br/>Private Const HEAP_GENERATE_EXCEPTIONS = &amp;H4<br/>Private Const NCBRESET = &amp;H32</p><p>Private Type NCB<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_command As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_retcode As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_lsn As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_num As Byte '' Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_buffer As Long ''String<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_length As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_callname As String * NCBNAMSZ<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_name As String * NCBNAMSZ<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_rto As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_sto As Byte '' Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_post As Long<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_lana_num As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_cmd_cplt As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_reserve(9) As Byte '' Reserved, must be 0<br/>&nbsp;&nbsp;&nbsp;&nbsp; ncb_event As Long<br/>End Type</p><p>Private Type ADAPTER_STATUS<br/>&nbsp;&nbsp;&nbsp;&nbsp; adapter_address(5) As Byte ''As String * 6<br/>&nbsp;&nbsp;&nbsp;&nbsp; rev_major As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; reserved0 As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; adapter_type As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; rev_minor As Byte ''Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; duration As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; frmr_recv As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; frmr_xmit As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; iframe_recv_err As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; xmit_aborts As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; xmit_success As Long<br/>&nbsp;&nbsp;&nbsp;&nbsp; recv_success As Long<br/>&nbsp;&nbsp;&nbsp;&nbsp; iframe_xmit_err As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; recv_buff_unavail As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; t1_timeouts As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; ti_timeouts As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; Reserved1 As Long<br/>&nbsp;&nbsp;&nbsp;&nbsp; free_ncbs As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_cfg_ncbs As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_ncbs As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; xmit_buf_unavail As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_dgram_size As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; pending_sess As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_cfg_sess As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_sess As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; max_sess_pkt_size As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; name_count As Integer<br/>End Type</p><p>Private Type NAME_BUFFER<br/>&nbsp;&nbsp;&nbsp;&nbsp; name As String * NCBNAMSZ<br/>&nbsp;&nbsp;&nbsp;&nbsp; name_num As Integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; name_flags As Integer<br/>End Type</p><p>Private Type ASTAT<br/>&nbsp;&nbsp;&nbsp;&nbsp; adapt As ADAPTER_STATUS<br/>&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;Dim myNcb As NCB<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim bRet As Byte<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_command = NCBRESET<br/>&nbsp;&nbsp;&nbsp;&nbsp; bRet = Netbios(myNcb)<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_command = NCBASTAT<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_lana_num = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_callname = "*       "<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim myASTAT As ASTAT, tempASTAT As ASTAT<br/>&nbsp;&nbsp;&nbsp;&nbsp; Dim pASTAT As Long<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_length = Len(myASTAT)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print Err.LastDllError<br/>&nbsp;&nbsp;&nbsp;&nbsp; pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, myNcb.ncb_length)<br/>&nbsp;&nbsp;&nbsp;&nbsp; If pASTAT = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "memory allcoation failed!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp; myNcb.ncb_buffer = pASTAT<br/>&nbsp;&nbsp;&nbsp;&nbsp; bRet = Netbios(myNcb)<br/>&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print Err.LastDllError<br/>&nbsp;&nbsp;&nbsp;&nbsp; CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)<br/>&nbsp;&nbsp;&nbsp; 'MsgBox Hex(myASTAT.adapt.adapter_address(0)) &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(1)) _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(2)) &amp; " " _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; Hex(myASTAT.adapt.adapter_address(3)) _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(4)) &amp; " " _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; Hex(myASTAT.adapt.adapter_address(5))<br/>&nbsp;&nbsp;&nbsp; ' HeapFree GetProcessHeap(), 0, pASTAT<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; Form1.Text1.Text = (myASTAT.adapt.adapter_address(0)) &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(1)) _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(2)) &amp; " " _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; Hex(myASTAT.adapt.adapter_address(3)) _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; " " &amp; Hex(myASTAT.adapt.adapter_address(4)) &amp; " " _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; Hex(myASTAT.adapt.adapter_address(5))<br/>&nbsp;Dim pangduan As String<br/>&nbsp;&nbsp;&nbsp;&nbsp; pangduan = "0 17 31 B5 AF C"<br/>&nbsp;'If Form2.Text1(0).Text = pangduan Then<br/>&nbsp;&nbsp;&nbsp; ' Form2.Command1.Enabled = True<br/>&nbsp;'Else<br/>&nbsp;&nbsp; ' MsgBox "对不起,您的网卡地址有误,请重新获取或检查网络配置"<br/>&nbsp;'End If</p><p>End Sub<br/></p>

wang_qiang 发表于 2007-8-26 16:16:00

<p>我试了以上代码,但显示的是"0 0 0 0 0 0",我的机子XP系统,请赐教.多谢</p>
页: [1]
查看完整版本: 在XP或WIN2000中怎样用VB得到计算机的网卡号