Stigatle.net

Site sponsored by Nettkroken.no

  • Increase font size
  • Default font size
  • Decrease font size
Home Maxscript Copy protecting MaxScripts - Using the license file

Copy protecting MaxScripts - Using the license file

E-mail Print PDF
Article Index
Copy protecting MaxScripts - Using the license file
Final script
Important info
All Pages

So now that we know how to get all the hardware info, and how to create and encrypt a license file it's time to put it to the test!

I spent a lot of time figuring out this one, at the end I found a easy and useable routine.

Create a license file  with the script in the previous article,
use the "get hardware lock" article to get your hardware lock number,
and use the "license generator" article to create your encrypted license.
Then make this one to test the system!

Again we create a new empty script (Utility).
Paste the following code:

 


utility copy_protected_script "Copy protected script" width:162 height:61
(
    button btn1 "Enabled if licensed" pos:[24,24] width:112 height:24 enabled:false

 

 )


This creates a new utility script, with a button, that is disabled by default.
What we want to do now is this:

when the user loads the script it should:

  1. check for a license.dat file.
  2. if there is none, then give error and stop.
  3. If there is license then check if it is the correct one for that computer.
  4. enable script if it is the correct license.

 

This is how:


utility copy_protected_script "Copy protected script" width:162 height:61
(
    button btn1 "Enabled if licensed" pos:[24,24] width:112 height:24 enabled:false 

     on copy_protected_script open do
     (

     )

)


The text marked in green is where we put the code to do all the things mentioned above.
Text marked with BLUE is what i put inside the GREEN code above.

 First we check for the license file:

on copy_protected_script open do
  (
       if doesFileExist "c:\lock.dat" ==false then
        (
            MessageBox "License not found.." title:"Error"
            return 0
        )

   )

 


This is where it get's a bit advanced. so please read carefully:

on copy_protected_script open do
  (
       if doesFileExist "c:\lock.dat" ==false then
        (
            MessageBox "License not found.." title:"Error"
            return 0
        )

 

if doesFileExist "c:\lock.dat" ==true then
        (
            btn1.enabled = true
        )
        f = openEncryptedFile "c:\lock.dat" 5476557
        id = readValue f
        close f
        if id != hardwareLockID then
        (
            btn1.enabled = false
            messagebox"License is not valid." title:"error"
            return 0
        )--end utility open

)

 


Breakdown:

 

  •  if doesFileExist "c:\lock.dat" ==true then --if the file exists (C:\lock.dat)
  • btn1.enabled = true --enable the button
  • f = openEncryptedFile "c:\lock.dat" 5476557 -- Opens the encrypted file with the KEY we set in the license generator
  • id = readValue f --gives the variable "id" the content of the keyfile (the hardware lock that we entered in the lic gen)
  • close f --closes the file
  • if id != hardwareLockID then --If the content (hwlock) is not the same as on the computer then
  • btn1.enabled = false --disable the button
  • messagebox"License is not valid." title:"error" --display messagebox
  • return 0 --stops the script

 




Last Updated on Tuesday, 30 December 2008 22:13