几何尺寸与公差论坛

 找回密码
 注册
查看: 901|回复: 0

【转帖】code for a trial

[复制链接]
发表于 2009-4-13 09:45:55 | 显示全部楼层 |阅读模式
code for a trial
hi,
i am new to vb so bare with me. i am trying to make my macro so that it has a 15 day trial period , that after it has been run once that it cannot after 15 days later. i have code that works
if date > #9/18/2008# then
msgbox "your trial period has ended"
end
end if
only thing is it leaves no log on the computer as to when it was first run and does not set the date accordingly.
i found this code on a site and the code is for an excel sheet could somebody make it so it would work for a sw macro?
dim swapp as object
option explicit
private sub workbook_open()
dim starttime#, currenttime#
'*****************************************
'set your own trial period below
'integers (1, 2, 3,...etc) = number of days use
'1/24 = 1hr, 1/48 = 30mins, 1/144 = 10mins use
const trialperiod# = 30 '< 30 days trial
'set your own obscure path and file-name
const obscurepath$ = "c:\"
const obscurefile$ = "testfilelog.log"
'*****************************************
if dir(obscurepath & obscurefile) = empty then
starttime = format(now, "#0.#########0")
open obscurepath & obscurefile for output as #1
print #1, starttime
else
open obscurepath & obscurefile for input as #1
input #1, starttime
currenttime = format(now, "#0.#########0")
if currenttime < starttime + trialperiod then
close #1
exit sub
else
if [a1] <> "expired" then
msgbox "sorry, your trial period has expired - your data" & vblf & _
"will now be extracted and saved for you..." & vblf & _
"" & vblf & _
"this workbook will then be made unusable."
close #1
saveshtsasbook
[a1] = "expired"
activeworkbook.save
application.quit
elseif [a1] = "expired" then
close #1
application.quit
end if
end if
end if
close #1
end sub
sub saveshtsasbook()
dim sheet as worksheet, sheetname$, myfilepath$, n&
myfilepath$ = activeworkbook.path & "\" & _
left(thisworkbook.name, len(thisworkbook.name) - 4)
with application
.screenupdating = false
.displayalerts = false
on error resume next '<< a folder exists
mkdir myfilepath '<< create a folder
for n = 1 to sheets.count
sheets(n).activate
sheetname = activesheet.name
cells.copy
workbooks.add (xlwbatworksheet)
with activeworkbook
with .activesheet
.paste
'//n.b. to remove all the cell formulas,
'//uncomment the 4 lines of code below...
'with cells
'.copy
'.pastespecial paste:=xlpastevalues
'end with
.name = sheetname
[a1].select
end with
'save book in this folder
.saveas filename:=myfilepath _
& "\" & sheetname & ".xls"
.close savechanges:=true
end with
.cutcopymode = false
next
end with
open myfilepath & "\read me.log" for output as #1
print #1, "thank you for trying out this product."
print #1, "if it meets your requirements, visit"
you can set it up to do a check out via your website. maybe have it create a file on your website, and then have it check that file each time the macro is run. if the file's date is past 15 days from the first install, then disable. one idea.
matt lorono
solidworks 2007 sp3.1
cad engineer/ecn analyst
there are a number of things to consider here.
matt's idea is one way to go. the only problem is that it forces the user to be connected to the internet.
if you write the install date to the registry, the "trial period" can easily be cracked by simply modifying the date. setting back the system clock to bypass the "trial period" is another issue. in vb.net you could store the install date using my.settings. once the program is installed and ran the first time, the date will be recorded. an easy way to bypass this is to uninstall the program and reinstall it. i am no expert in the field but here is an idea. you can record the date each time the program is run. if the clock is set back, you can do a simple check against the last run time and the current time. if the current time is less than the last run time, obviously someone is trying to bypass your system.
i guess all in all, encrypting the install date and saving it in the registry somewhere is the way to go. as far as the registry key goes, do not name it anything pertaining to your program. it is still easy to find, but a lot more difficult for the novice user. encryption can be cracked as well, but it can be very difficult and/or time consuming.
with that said, you should always check the last run date against the install date as i stated above. the last run date can also be stored in a registry key.
i am sure there are more ways to do this, but this is my opinion. i hope it helps a bit.
tony szuta
cswa, cswp, cswp-smtl
thanks for the replies. i guess in vb, macro's are pretty hard to protect being that there is no way to keep your code from being seen even if you password protect the code. i like the idea of making it check back to your website then they user cannot change the time on his computer to make it work. but i guess not all people have a fast internet connection. i like the idea of making it check back to see the last run date or intstall date. the average joe they would not know where to find the log in the registry to delete it . thanks for your opinions.
look into "armadillo" software. armadillo adds license keys to applications.
i have not tried it on macros, but it works on addins.
cleon,
your typical solidworks user isn't going to be able to crack the password on the .swp file. a way to make this stronger is to user a wide array of characters, upper and lower case along with symbols. make the password long as well. users that really want to get into your project will need try to use a brute force method. by using 9 characters and the convention as i noted above, it will take a rather lengthy amount of time to go through every possible password combination.
the possible number of combinations for a 9 character password (uppercase, lowercase, and symbols) is 84 to the 9th power or 2.0821574853093e+17 possible combinations.
by lengthy time, i mean years...
tony szuta
cswa, cswp, cswp-smtl
you could use registry entries to keep track of versions, install dates, etc.
so, how do you put a password on a swp file?
dan miel
2008
dan,
if your comment was directed towards me, i was referring to protecting the vba project, not the macro file itself.
tony szuta
cswa, cswp, cswp-smtl
hi tony,
cracking a password with symbols and letters lower case and upper case would take a lot of time but there is a very easy way to just erase the password with out even trying to crack it and just make a new password of your choice and then you can open it in a mater of seconds
edited: 09/17/2008 at 05:01 pm by cleon martin
dan,
if you just click on tools project properties under the protection tab there you can put in a password and then save it and the next time you open it you will have to enter your password in order to see the code.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-24 09:00 , Processed in 0.038240 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表