LISP如何实现限制使用时间(网络时间)?到期后不能使用。
LISP如何实现限制使用时间(网络时间)?到期后不能使用。;;---------------------=={ Internet Time }==------------------;;
;; ;;
;;Returns the date and/or UTC time as a string in the ;;
;;format specified. Data is sourced from a NIST server. ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;format - string specifying format of returned information ;;
;; using the following identifiers to represent ;;
;; date & time quantities: ;;
;; YY = Year, MO = Month, DD = Day ;;
;; HH = Hour, MM = Minutes, SS = Seconds ;;
;;------------------------------------------------------------;;
;;Returns:String containing formatted date/time data ;;
;;------------------------------------------------------------;;
(defun LM:InternetTime ( format / result rgx server xml )
(setq server "http://time.nist.gov:13")
(setq result
(vl-catch-all-apply
(function
(lambda ( / str )
(setq xml (vlax-create-object "MSXML2.XMLHTTP.3.0"))
(setq rgx (vlax-create-object "VBScript.RegExp"))
(vlax-invoke-method xml 'open "POST" server :vlax-false)
(vlax-invoke-method xml 'send)
(if (setq str (vlax-get-property xml 'responsetext))
(progn
(vlax-put-property rgx 'global actrue)
(vlax-put-property rgx 'ignorecase actrue)
(vlax-put-property rgx 'multilineactrue)
(mapcar
(function
(lambda ( a b )
(vlax-put-property rgx 'pattern a)
(setq format (vlax-invoke rgx 'replace format b))
)
)
'("YY" "MO" "DD" "HH" "MM" "SS")
'("$1" "$2" "$3" "$4" "$5" "$6")
)
(vlax-put-property rgx 'pattern
(strcat
"(?:[^\\d]+[\\d]+[^\\d]+)"
"([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)"
"([\\d]+)(?:[^\\d]+)([\\d]+)(?:[^\\d]+)([\\d]+)(?:.+)\\n"
)
)
(vlax-invoke-method rgx 'replace str format)
)
)
)
)
)
)
(if xml(vlax-release-object xml))
(if rgx(vlax-release-object rgx))
(if (not (vl-catch-all-error-p result))
result
)
)
The 'format' parameter
This parameter is a string specifying the format for the returned data. It is used in a similar way to the 'picture' parameter for the edtime DIESEL function, using the following identifiers to represent date & time quantities:
Code:
YY=Year
MO=Month
DD=Day
HH=Hours
MM=Minutes
SS=Seconds
Examples
Code:
_$ (LM:InternetTime "DD/MO/YY, HH:MM:SS")
"17/09/11, 19:37:07"
Code:
_$ (LM:InternetTime "MO.DD.YY")
"09.17.11"
Code:
_$ (LM:InternetTime "HH:MM")
"19:37"
本帖最后由 xshrimp 于 2022-6-2 09:24 编辑
;;;xshrimp 2022.06.01
(defun xzj-InternetTime( / fs timeStr tmpFile true ts wscript)
(setq tmpFile (vl-filename-mktemp nil nil ".txt"))
(setq wscript (vlax-create-object "wscript.shell"))
(setq fs (vlax-create-object "scripting.filesystemobject"))
(vlax-invoke wscript 'run (strcat "cmd.exe /c curlhttps://www.beijing-time.org/t/time.asp>\"" tmpFile "\"")0 1)
(setq ts (vlax-invoke fs 'opentextfile tmpFile1 -1));true -1
(setq timeStr (vlax-invoke ts 'readall))
(vlax-invoke ts 'Close)
(vlax-invoke fs 'DeleteFile tmpFile)
(alert timeStr)
)
(xzj-InternetTime)
没有网络如何处理?还是用系统时间控制比较容易些。 获取初次试用时间,保存
以后每次用的时候取当前时间,和保存的时间比较,看看用了多少天了,过期就不运行 要么联网获取真实时间,同时承担没网络不能运行的后果。要么获取本地时间,同时承担用户修改时间跳过的后果。根据需要选择合适的验证方式。 xshrimp 发表于 2022-5-31 15:27
The 'format' parameter
This parameter is a string specifying the format for the returned data ...
老哥没用,放回nil xshrimp 发表于 2022-6-1 17:49
;;;xshrimp 2022.06.01
(defun xzj-InternetTime( / fs timeStr tmpFile true ts wscript)
(setq tmpFi ...
如果tmpFile空,则(setq timeStr (vlax-invoke ts 'ReadAll))失败,为什么会空呢? 本帖最后由 xshrimp 于 2022-6-2 09:21 编辑
自贡黄明儒 发表于 2022-6-2 07:49
如果tmpFile空,则(setq timeStr (vlax-invoke ts 'ReadAll))失败,为什么会空呢?
执行太快,文件还没有写入数据,就读.文件为空.
或者没有读就删了?
已经修改了.你再试下呢
页:
[1]
2