Like Mike said is good, also, if they backdate the PC, then, you can halt the application. So, you have to stamp the install date and the Expiration date. or simply, just the install date and then always check if the Date() > InsTallDate+30 to expire.
Now, if Date() < Install Date, you can warn him and kick him out of the app.
Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
Rather than put it in the Registry, you could write the date to a hidden file to some obscure part of the hard drive. It's too easy for a knowledgeable user to edit the Registry.
>> Hello,I would like to know how to limit the use of my application for 30 days. As if it was a demo or an evaluation copy. <<
Here is some code that I wrote back in 1996 to do just this. Make sure that you create the file as part of the installation process using code like this:
lcDateFile = GETENV('WINDIR') + "\WINSLM.TXT"
IF FILE(lcDateFile)
lnFileHandle = FOPEN(lcDateFile,12) && open it read/write
ELSE
lnFileHandle = FCREATE(lcDateFile, 0) && create it
ENDIF
IF lnFileHandle = -1
WAIT WINDOW "Cannot open system file"
RETURN
ENDIF
lcDate = DTOS(DATE()+30)
lnCodedDate = VAL(lcDate) + 16927438
lcSubDate = ALLTRIM(STR(lnCodedDate))
lcCodedDate = ""
FOR lni = 1 TO 8
lcDigit = CHR(VAL(SUBSTR(lcSubDate, lni, 1)) + 65)
lcCodedDate = lcCodedDate + lcDigit
ENDFOR
lnDateWritten = FPUTS(lnFileHAndle, lcCodedDate)
IF lnDateWritten = 0
WAIT WINDOW "Unable to write to system file..."
ENDIF
DO WHILE !FCLOSE(lnFileHandle)
ENDDO
Then, add a function called NotExpired() to your main program and call it when the applicaytion starts up. Here is the code for NotExpired:
********************************************************************
* FUNCRION NotExpired()
**********************************************************************
* Description........: Returns .T. if program is not expired
FUNCTION NotExpired()
LOCAL lcCodedDate, lcSetDate, lni, lcDigit, lcUncodedDate, ;
lnUnCodedDate, lcSubDate, ldFinalDate, lnDigit, lcDateFile, ;
lnFileHandle, lcDays
IF FILE("Customer.Txt") OR FILE("Tsc.txt") OR FILE("Devel.Txt")
RETURN .T.
ENDIF
lcDateFile = GETENV('WINDIR') + "\WINSLM.TXT"
IF !FILE(lcDateFile)
=MESSAGEBOX("Missing System File...Can NOT Run Program", MB_ICONSTOP, APPNAME_LOC)
RETURN .F.
ENDIF
lnFileHandle = FOPEN(lcDateFile,10)
IF lnFileHandle = -1
=MESSAGEBOX("Cannot open system file", MB_ICONSTOP, APPNAME_LOC)
RETURN .F.
ENDIF
lcCodedDate = FGETS(lnFileHandle,8)
=FCLOSE(lnFileHandle)
lcSetDate = SET("DATE")
SET CENTURY ON
lcUnCodedDate = ""
FOR lni = 1 TO 8
lnDigit = ASC(SUBSTR(lcCodedDate, lni, 1)) - 65
lcUnCodedDate = lcUnCodedDate + ALLTRIM(STR(lnDigit))
ENDFOR
lnUnCodedDate = VAL(lcUncodedDate) - 16927438
lcUncodedDate = ALLTRIM(STR(lnUncodedDate))
lcSubDate = SUBSTR(lcUncodedDate,5,2)+"/"+RIGHT(lcUncodedDate,2)+"/"+LEFT(lcUncodedDate,4)
set date MDY
ldFinalDate = CTOD(lcSubDate)
IF ldFinalDate < DATE()
=MESSAGEBOX("Program has expired...", MB_ICONSTOP, APPNAME_LOC)
SET DATE &lcSetDate
RETURN .F.
ELSE
IF ldFinalDate < DATE() + 30
lcDays = ALLTRIM(STR(ldFinalDate - DATE()))
=MESSAGEBOX("Program will expire in "+lcDays+" days!", MB_ICONINFORMATION, APPNAME_LOC)
SET DATE &lcSetDate
RETURN .T.
ELSE
SET DATE &lcSetDate
RETURN .T.
ENDIF
ENDIF
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.