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
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
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.
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.Please Login or Register to view this content.
thank you very much for the response
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.
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 ...
If I come up with another idea, I'll post it here.But, as with most things, an experienced Excel hacker could figure this out pretty quickly.
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.
thnx for the help
yes, i've realized nothing is foolproofed, but i just want something that is not too easy to get by
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
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.
i think i might have misrepresented myself because these codes flew by me looking at it
been trying to mess with them, got nowhere
how would you add this part
to the original codeOriginally Posted by MSP77079
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
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:
And, here is the new code to check dates:Please Login or Register to view this content.
Please Login or Register to view this content.
Correct. This would be something like:strFile would be the location for the file to be saved
strFile = "C:\myFolder\myFile.ini"
The subroutine "Sub tempToolbarWriteLocation" is doing the writing. So, for example, this linewhat is being written into the file?
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.Please Login or Register to view this content.
The subroutine "Sub tempToolbarReadLocation" is calls for the reading. This line of codeon the readIn function, what is the variable that the stuff from the external file going to be saved on?
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.Please Login or Register to view this content.
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.
thank you.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks