Posted on 2005-05-08
Last Modified: 2010-04-23
I have written a VB.NET 2003 application which I would like to reduce the possibilities of people making illegal copies. Therefore, I wrote some code that when the program is run for the first time, it gererates a random code. The user must then e-mail or phone me and read this number to me. I then type it into a little program I wrote which performs some simple calculations on it and spits out another code. I then give this to the client to punches it into the program. The program performs the same calculation on the original number, and if it matches the number I gave him, it unlocks the program. It can even unlock the program for a certain number of days (basically extend the trial period) depending on what code I give him. Just two problems:

1. The trial number of days left / unlock status is stored in the registry and can therefore be modified my anyone with some Windows knowledge. What is the best way to encrypt this number?

2. Is there a program or code that does more or less what Windows XP Activation does - where instead of randomly generating a number when the program is run for the first time, it generates a number based on the user's hardware? That way I can tell if he is installing it on another machine if he phones trying to get another unlock key. Also, if he formats and reinstalls the program, the same unlock her from before will still work.

Question by:SETP
    LVL 21

    Assisted Solution

    Hi SETP,
    > generates a number based on the user's hardware
    Try this:
    Hope It helps
    LVL 14

    Assisted Solution

    LVL 6

    Accepted Solution


    I'm currently developing a piece of software that will do a hardware and software inventory of all computers, and what I've found best to use for secure identification is CPU id and BIOS id.

    These can be retrieved by using WMI, as in my example below.
    WMI is very powerful and can be used to get all available info about the computer.

    Check here if you want to know about additional WMI classes available:

    Btw, the code below is VB6, but should easily be able to port it to .NET

    / Jon

    'Add the following code to a module (called e.g. WMI)
    Option Explicit

    Private m_mainWmi As Object
    Private m_deviceLists As Collection

    Private Function GetMainWMIObject() As Object
      On Error GoTo eh
      If m_mainWmi Is Nothing Then
        Set m_mainWmi = GetObject("WinMgmts:")
      End If
      Set GetMainWMIObject = m_mainWmi
      Exit Function
      Set GetMainWMIObject = Nothing
    End Function

    Public Function WmiIsAvailable() As Boolean
      WmiIsAvailable = CBool(Not GetMainWMIObject Is Nothing)
    End Function

    Public Function GetWmiDeviceSingleValue(ByVal WmiClass As String, ByVal WmiProperty As String) As String
      On Error GoTo done
      Dim result As String
      Dim wmiclassObjList As Object
      Set wmiclassObjList = GetWmiDeviceList(WmiClass)
      Dim wmiclassObj As Object
      For Each wmiclassObj In wmiclassObjList
        result = CallByName(wmiclassObj, WmiProperty, VbGet)
        Exit For

      GetWmiDeviceSingleValue = Trim(result)
    End Function

    Public Function GetWmiDeviceList(ByVal WmiClass As String) As Object
      If m_deviceLists Is Nothing Then
        Set m_deviceLists = New Collection
      End If
      On Error GoTo fetchNew
      Set GetWmiDeviceList = m_deviceLists.Item(WmiClass)
      Exit Function
      Dim devList As Object
      Set devList = GetWmiDeviceListInternal(WmiClass)
      If Not devList Is Nothing Then
        Call m_deviceLists.Add(devList, WmiClass)
      End If
      Set GetWmiDeviceList = devList
    End Function

    Private Function GetWmiDeviceListInternal(ByVal WmiClass As String) As Object
      On Error GoTo eh
      Set GetWmiDeviceListInternal = GetMainWMIObject.Instancesof(WmiClass)
      Exit Function
      Set GetWmiDeviceListInternal = Nothing
    End Function


    ' then anywhere in your program you could write the fllowing to get the id:s

      Dim CPU As String
      CPU = GetWmiDeviceSingleValue("Win32_Processor", "ProcessorID")
      Dim BIOS As String
      BIOS = GetWmiDeviceSingleValue("Win32_BIOS", "SerialNumber")

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now