Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to limit an a application?

Status
Not open for further replies.

foxfito

Programmer
Sep 29, 2003
15
0
0
EC
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.
 
foxfito

You could stamp the date it got installed on the computer in the registry. But the user could back-date his system.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
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.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top