几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 09:45 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】code for a trial

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.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 07:09 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多