Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Trying to get code to identify/read mac id while installing a certain program and the system to validate the mac id when the program is run in future. If the program files are copied to different system then it should not run. This program to support possible all operating systems and configurations.

Thanks in advance
Posted
Updated 10-Nov-12 23:30pm
v2
Comments
Nelek 11-Nov-12 5:47am    
Ok, you are trying. And where are you having problems?

Bad idea.
1. A honest user upgrades a network card: your program stops working.
2. A evil user sets up a virtual PC, installs your program, saves the image, uploads it to the Web and shares your app with whoever is smart enough to install a virtual PC.

If you want software rights management, or activation, you need a more complex solution. If you're planning to sell your software, consider a commercial solution. I won't provide any links, since nobody is paying me any percentages, but googling a bit should help.

JM2B,

Pablo.
 
Share this answer
 
From MSDN Q118623 HOWTO: Get the MAC Address for an Ethernet Adapter


VB
Option Explicit
' net config workstation

' from NB30.h

'#define NCBNAMSZ        16    /* absolute length of a net name           */
'#define MAX_LANA       254    /* lana's in range 0 to MAX_LANA inclusive */
'#define NCBENUM         0x37            /* NCB ENUMERATE LANA NUMBERS         */

Private Const NCBNAMSZ = 16
Private Const MAX_LANA = 254

Private Const NCBRESET = &H32
Private Const NCBASTAT = &H33
Private Const NCBENUM = &H37

Private Type NCB
    ncb_command As Byte ' APIViewer defines this incorrectly as Integer
    ncb_retcode As Byte ' APIViewer defines this incorrectly as Integer
    ncb_lsn As Byte ' APIViewer defines this incorrectly as Integer
    ncb_num As Byte ' APIViewer defines this incorrectly as Integer
    ncb_buffer As Long ' APIViewer defines this incorrectly as String
    ncb_length As Integer
    ncb_callname As String * NCBNAMSZ
    ncb_name As String * NCBNAMSZ
    ncb_rto As Byte ' APIViewer defines this incorrectly as Integer
    ncb_sto As Byte ' APIViewer defines this incorrectly as Integer
    ncb_post As Long
    ncb_lana_num As Byte ' APIViewer defines this incorrectly as Integer
    ncb_cmd_cplt As Byte  ' APIViewer defines this incorrectly as Integer
    ncb_reserve(0 To 9) As Byte ' Reserved, must be 0, ' APIViewer defines this incorrectly as (10)
    ncb_event As Long
End Type

Private Type LANA_ENUM
        Length As Integer
        Lana(0 To MAX_LANA) As Integer
End Type

'#define NRC_GOODRET     0x00    /* good return                                */
Private Const NRC_GOODRET = 0

Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte

Private Type ADAPTER_STATUS
    adapter_address(0 To 5) As Byte             'As String * 6
    rev_major As Byte           ' APIViewer defines this incorrectly as Integer
    reserved0 As Byte           ' APIViewer defines this incorrectly as Integer
    adapter_type As Byte         ' APIViewer defines this incorrectly as Integer
    rev_minor As Byte           ' APIViewer defines this incorrectly as Integer
    duration As Integer
    frmr_recv As Integer
    frmr_xmit As Integer
    iframe_recv_err As Integer
    xmit_aborts As Integer
    xmit_success As Long
    recv_success As Long
    iframe_xmit_err As Integer
    recv_buff_unavail As Integer
    t1_timeouts As Integer
    ti_timeouts As Integer
    Reserved1 As Long
    free_ncbs As Integer
    max_cfg_ncbs As Integer
    max_ncbs As Integer
    xmit_buf_unavail As Integer
    max_dgram_size As Integer
    pending_sess As Integer
    max_cfg_sess As Integer
    max_sess As Integer
    max_sess_pkt_size As Integer
    name_count As Integer
End Type
   
Private Type NAME_BUFFER
    name As String * NCBNAMSZ
    name_num As Integer
    name_flags As Integer
End Type

Private Type ASTAT
     adapt As ADAPTER_STATUS
     NameBuff(30) As NAME_BUFFER        ' ?? 30 or 0 to 29 aod
End Type

   

' From MSDN Q118623 HOWTO: Get the MAC Address for an Ethernet Adapter

Public Function LANA_List() As Variant
    Dim NCB As NCB
    Dim LANA_ENUM As LANA_ENUM

'      Ncb.ncb_command = NCBENUM;
    NCB.ncb_command = NCBENUM
    
'      Ncb.ncb_buffer = (UCHAR *)&lenum;
    NCB.ncb_buffer = VarPtr(LANA_ENUM)
'      Ncb.ncb_length = sizeof(lenum);
    NCB.ncb_length = Len(LANA_ENUM)
    
'      uRetCode = Netbios( &Ncb );
    Dim Ret As Byte
    Ret = Netbios(NCB)
    If Ret <> NRC_GOODRET Then
        Err.Raise 5, , "LANA_lst: Error from Netbios, return code = " & Ret
    End If
    
    ' copy array to a nice variant array. VB Style
    If LANA_ENUM.Length > 0 Then
        ReDim List(LANA_ENUM.Length - 1)
    
        Dim Index As Long
        For Index = 0 To LANA_ENUM.Length - 1
           List(Index) = LANA_ENUM.Lana(Index)
        Next Index
        LANA_List = List
    Else
        LANA_List = Array()
    End If
End Function


Public Function MacAddress(ByVal LANA_Number_IN As Long) As String
    Dim NCB As NCB
    Dim Ret As Byte
    
    NCB.ncb_command = NCBRESET
    Ret = Netbios(NCB)
    If Ret <> NRC_GOODRET Then
        Err.Raise 5, , "MacAddress: Error from Netbios, return code = " & Ret
    End If
    
    NCB.ncb_command = NCBASTAT
    NCB.ncb_lana_num = LANA_Number_IN
    NCB.ncb_callname = "*"
    Debug.Assert NCB.ncb_callname = "*               "
    
    Dim ASTAT As ASTAT
    NCB.ncb_length = Len(ASTAT)
    Debug.Assert NCB.ncb_length = 680
    NCB.ncb_buffer = VarPtr(ASTAT)
    Ret = Netbios(NCB)
    If Ret <> NRC_GOODRET Then
        Err.Raise 5, , "MacAddress: Error from Netbios, return code = " & Ret
    End If
    
    ' this should be returned as an array of bytes someday
    MacAddress = Hex(ASTAT.adapt.adapter_address(0)) & " " & _
           Hex(ASTAT.adapt.adapter_address(1)) _
           & " " & Hex(ASTAT.adapt.adapter_address(2)) & " " _
           & Hex(ASTAT.adapt.adapter_address(3)) _
           & " " & Hex(ASTAT.adapt.adapter_address(4)) & " " _
           & Hex(ASTAT.adapt.adapter_address(5))
    'Debug.Print MacAddress
End Function


Sub main()
    Dim Lana As Variant
    
    ' this will return multiple LANA when connected to a dial up connection & a NIC
    For Each Lana In LANA_List
        Debug.Print Lana, MacAddress(Lana)
    Next Lana
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900