Private Declare Function RegOpenKeyA Lib "ADVAPI32.DLL" (ByVal hKey As Long, ByVal sSubKey As String, ByRef hkeyResult As Long) As Long
Private Declare Function RegCloseKey Lib "ADVAPI32.DLL" (ByVal hKey As Long) As Long
Private Declare Function RegSetValueExA Lib "ADVAPI32.DLL" (ByVal hKey As Long, ByVal sValueName As String, ByVal dwReserved As Long, ByVal dwType As Long, ByVal sValue As String, ByVal dwSize As Long) As Long
Private Declare Function RegCreateKeyA Lib "ADVAPI32.DLL" (ByVal hKey As Long, ByVal sSubKey As String, ByRef hkeyResult As Long) As Long
Private Declare Function RegQueryValueExA Lib "ADVAPI32.DLL" (ByVal hKey As Long, ByVal sValueName As String, ByVal dwReserved As Long, ByRef lValueType As Long, ByVal sValue As String, ByRef lResultLen As Long) As Long
' Equivalent of OnLoad Behavior , Check if product is activated or have been moved and report
Private Sub Workbook_Open()
' If Not (FileExists("License Manager_O.exe")) Then
'MsgBox "Software was copied or moved illegaly ! ", vbCritical + vbOKOnly, "SPS (Software Protection System)"
'Application.Quit
'Else
If Not (isactivated()) Then
MsgBox "Your Product is not activated, Please Run <Oscar A User 2010> to proceed with activation ", vbInformation + vbOKOnly, "SPS (Software Protection System)"
Dim dblShellRetn As Double
ThisWorkbook.Close Savechanges:=False
Application.Quit
'End If
End If
End Sub
' Check if License Manager is at the same relative position as the workbook
Private Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(Me.Path + "\res\" + fname)
MsgBox x, vbCritical + vbOKOnly, "SPS (Software Protection System) , Violation Error"
If x <> "" Then FileExists = True _
Else: FileExists = False
End Function
' Read the registry using GetRegistry Function and return result
Private Function isactivated() As Boolean
RootKey = "HKEY_CLASSES_ROOT"
Path2 = ".iia"
RegEntry = "Printf"
If (GetRegistry(RootKey, Path2, RegEntry) = "0") Then
isactivated = False
Else
If (GetRegistry(RootKey, Path2, RegEntry) = "299B6") Then
isactivated = True
Else
isactivated = False
End If
End If
End Function
' Function GetRegistry reads the registry and look for activation indicator key
Function GetRegistry(Key, Path, ByVal ValueName As String)
Dim hKey As Long
Dim lValueType As Long
Dim sResult As String
Dim lResultLen As Long
Dim ResultLen As Long
Dim x, TheKey As Long
Select Case UCase(Key)
Case "HKEY_CLASSES_ROOT": TheKey = &H80000000
Case "HKEY_CURRENT_USER": TheKey = &H80000001
Case "HKEY_LOCAL_MACHINE": TheKey = &H80000002
Case "HKEY_USERS": TheKey = &H80000003
Case "HKEY_CURRENT_CONFIG": TheKey = &H80000004
Case "HKEY_DYN_DATA": TheKey = &H80000005
End Select
If RegOpenKeyA(TheKey, Path, hKey) <> 0 Then _
x = RegCreateKeyA(TheKey, Path, hKey)
sResult = Space(100)
lResultLen = 100
x = RegQueryValueExA(hKey, ValueName, 0, lValueType, _
sResult, lResultLen)
Select Case x
Case 0: GetRegistry = Left(sResult, lResultLen - 1)
Case Else: GetRegistry = "0"
End Select
RegCloseKey hKey
End Function
-1