Hi All,
I have attached a sample file which has the codes to generate an activation key based on the hard disk volume id and 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 on this. How do I write the "Key" in windows registry and check the key on loading the add-in
Thanks in advance!
Code
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[attach=1232532][/attach]
Display More