+ Reply to Thread
Results 1 to 14 of 14

set expiration date

  1. #1
    Registered User
    Join Date
    12-26-2006
    Posts
    14

    set expiration date

    I have an excel program that I want to set an expiration date on it, such as 30 days from the first time it's opened. After 30 days, activeworkbook.close

    any help at all would be appreciated

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    The only issue is how to "save" the date of first use.

    Example below uses a Name in the workbook for this. I have made the Name invisible, so that most users cannot find it. But, as with most things, an experienced Excel hacker could figure this out pretty quickly.

    As written, this code will only work for the next ~1500 years. After that, you will need new code.

    Please Login or Register  to view this content.
    Here is code to "reset" the workbook.

    Please Login or Register  to view this content.
    Another option would be to create a Windows registry entry. Still not foolproof, though.

  3. #3
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    thank you very much for the response

  4. #4
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    is there a way that i can import a date from a website for useDate because it seems that I can just change my system clock to bypass this rather easily.

    I tried to import date onto the excel sheet but it doesn't work after i password protect the sheet, so now i'm kinda stuck and not sure what to do.
    Last edited by nhat8121; 12-26-2006 at 09:45 PM.

  5. #5
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    That is a very interesting observation. I will have to think about it.

    Maybe that is why Microsoft has the limit they do on registering software. Namely, you can use it 50 times without registering it; but, after 50 times, it will no longer function (completely; you can still view files you created, but you cannot edit and save them, nor create new ones).

    This is why I wrote earlier ...

    But, as with most things, an experienced Excel hacker could figure this out pretty quickly.
    If I come up with another idea, I'll post it here.

  6. #6
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    OK ... this is what I came up with.

    You already have one variable (useDate) to save "Today + 30 days" and, at each start-up, compare "Today" with useDate.

    What if you have a second variable (checkDate) to save "Today"; and, at each start-up compare "Today" with checkDate. If you ever find that checkDate is greater than the current system clock date, this would also trigger the deactivation.

    To make the process more effective, and to limit someone's ability to test your defenses, why not also delete the file, rather than simply not let it open?

    Since you cannot delete a file from code within an open file, this would require that you create a separate app to do this. But, that is simple to do using VBScript. (Your Excel program would create a VBScript application in the user's Temp directory. The VBScript would run in a loop until the the file was deleted.)

    Next thing to worry about is a user saving multiple copies of your program and using a "fresh" copy each time. To protect against this, you would need to save your two variables (useDate and checkDate) somewhere other than as Names in the Excel file itself. You could use either the Windows Registry, or it's own .ini File.

    As I said in my original posting, none of this is fool-proof. I am only telling you about security I have seen (and defeated) in the past. But, the vast majority of people would not be up to the challenge.

  7. #7
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    thnx for the help

    yes, i've realized nothing is foolproofed, but i just want something that is not too easy to get by

  8. #8
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    how do i go about saving the date onto an .ini file in the temp directory? is it better to save there or in windows registry? it just seems too invasive using windows registry lol

  9. #9
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    You do not want to save the *.ini file in the user’s temp directory. The temp directory is wiped clean whenever the user boots up, and the idea of the *.ini file is to have something what will be remembered between sessions.

    The choice of *.ini file vs. Windows registry is somewhat arbitrary. But, I understand the reluctance to mess around with the registry.

    If you use a *.ini file, you probably want to put in a path like:
    C:\WINDOWS or
    C:\WINDOWS\system32

    Below is example code required. The first lines are declaration statements for Win32 API which read from and write to an *.ini file (which is really just a text file that has text in a certain format). One nice feature is that if the file does not exist (but the folder does), the Win32API will create the *.ini file for you.

    Next are 2 functions, one to read, one to write.

    Finally are 2 example subroutines; in these examples, the subroutine are reading / writing the location of a toolbar.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    i think i might have misrepresented myself because these codes flew by me looking at it

    been trying to mess with them, got nowhere

  11. #11
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    how would you add this part
    Quote Originally Posted by MSP77079
    What if you have a second variable (checkDate) to save "Today"; and, at each start-up compare "Today" with checkDate. If you ever find that checkDate is greater than the current system clock date, this would also trigger the deactivation.
    to the original code

    i tried and somehow i reset firstuse date and it's just all messy

    i understand the concept, but i'm practically retarded when it comes to coding

  12. #12
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Don't be so hard on yourself. If you have not used Win32 API before, then there is no way you could expect to really understand what I posted last time. It will come with time.

    Meanwhile ... here is the new code to "reset" the workbook:

    Please Login or Register  to view this content.
    And, here is the new code to check dates:

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    strFile would be the location for the file to be saved
    Correct. This would be something like:
    strFile = "C:\myFolder\myFile.ini"

    what is being written into the file?
    The subroutine "Sub tempToolbarWriteLocation" is doing the writing. So, for example, this line
    Please Login or Register  to view this content.
    calls the writeINI32 function. After creating an ini file using this code, open it with Notepad. You will see immediately what "Section" and "Key" mean.

    on the readIn function, what is the variable that the stuff from the external file going to be saved on?
    The subroutine "Sub tempToolbarReadLocation" is calls for the reading. This line of code
    Please Login or Register  to view this content.
    calls the "readINI32" function asking for the value relating to the "Section" named "PositionToolbar" and "key" named "Position". Since the ini file is a text file, this is returning a text; so, I need Val() to convert the text into a number.

    In your case, you would need DateValue(), or some other logic, to convert the text into a date. Speaking of which, you then either want to write those dates in Excel date format (a long integer) or in an international format (such as yyyy-mm-dd) so that you will reliably get the same date returned no matter what format the user's machine is set up for.

  14. #14
    Registered User
    Join Date
    12-26-2006
    Posts
    14
    thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1