Results 1 to 20 of 20

Thread: How can I create product keys for VBA add-ins and store it in the system?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Hi,
    I have revised the codes based on the hard disk volume id. I have also got sample codes to read and write the registry keys. However, not sure how to make it work and request some help in making it work.

    Option Explicit
    Public Key        As String, Strg   As String
    
    Sub CreateActivationKey()    
    Dim i      As Long
        Strg = DiskVolumeId(Environ("SystemDrive"))
        For i = 1 To Len(Strg)
            Key = Key & Hex(Asc(Mid(Strg, i, 1)))
        Next i
    End Sub
    
    
    Function DiskVolumeId(Drive As String) As String
        Dim sTemp  As String
        Dim iPos   As Long
        iPos = InStr(1, Drive, ":")
        Drive = IIf(iPos > 0, Left(Drive, iPos), Drive & ":")
        sTemp = Hex(CreateObject("Scripting.FileSystemObject") _
                .Drives.Item(CStr(Drive)).SerialNumber)
        DiskVolumeId = Left(sTemp, 4) & "-" & Right(sTemp, 4)
    End Function
    Function RegKeyRead(i_RegKey As String) As String    
    Dim myWS   As Object
    
        On Error Resume Next
        Set myWS = CreateObject("WScript.Shell")
        RegKeyRead = myWS.RegRead(i_RegKey)
    End Function
    
    
    Sub RegKeySave(i_RegKey As String, _
        i_Value As String, _
        Optional i_Type As String = "REG_DWORD")
        Dim myWS   As Object
    
    
        Set myWS = CreateObject("WScript.Shell")
        myWS.RegWrite i_RegKey, i_Value, i_Type
        
    End Sub
    
    
    Function RegKeyExists(i_RegKey As String) As Boolean
        Dim myWS   As Object
    
    
        On Error GoTo ErrorHandler
        Set myWS = CreateObject("WScript.Shell")
        myWS.RegRead i_RegKey
        RegKeyExists = True
        Exit Function
        
    ErrorHandler:
        RegKeyExists = False
    End Function
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •