Hello Foxfito.
>> 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:
LOCAL lcCodedDate, lcSetDate, lni, lcDigit, ;
lnCodedDate, lcSubDate, lcDigit, lcDateFile, ;
lnFileHandle, lcDate, lnDateWritten
lcSetDate = SET("DATE")
SET CENTURY ON
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
Marcia G. Akins