关于U盘获取PNPDeviceID会变问题
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=175414&page=61&extra=#pid992500(2019.5.27上传优化版示例-仅供参考)全盘符选择注册加密代码用 fangmin723 大师的全盘符选择注册加密代码 中发现部分U盘申请发会变法,在不同中计算出来的 (vlax-get n 'PNPDeviceID) 中含有&连接符号,就会导致LST1会变法。
我自己电脑获取的为 ((2 "6&26BC55B9&0&_&0"))
我朋友电脑获取的为 ((2 "6&2CB6BAA1&0&_&0"))
请大师们是什么问题造成的。
(defun BF-str->lst (str del / pos)
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos)
(BF-str->lst (substr str (+ pos 1 (strlen del))) del)
)
(list str)
)
)
(defun bf-LIST-SORT (lst oper / x1 x2)
(vl-sort lst
'(lambda (x1 x2)
(if
(and
(atom x1)
(atom x2)
)
(apply oper (list x1 x2))
(apply oper (list (car x1) (car x2)))
)
)
)
)
(defun getpathsn(/ drives found fso lst lst1 meth1 meth2 meth3 n path pclst pflst serialnumber uplst volumename wmi)
;;;↓↓↓↓↓↓↓↓获取PC序列号↓↓↓↓↓↓↓↓
(setq fso (vlax-create-object "Scripting.FileSystemObject"))
(setq Drives (vlax-get-property fso "Drives") pclst nil uplst nil)
(vlax-for n drives
(and
(= 2 (vlax-get-property n 'DriveType));2 DriveType 本地磁盘
(setq Path (vlax-get-property n 'Path))
(setq SerialNumber (vl-princ-to-string(vlax-get-property n 'SerialNumber)))
(setq pclst (cons (list (vl-string-trim "\" :" Path) (strcat "PC" (substr (sernumConfused SerialNumber) 1 16))) pclst));电脑盘符路径及序列号表
)
)
;;;↓↓↓↓↓↓↓↓获取UP序列号↓↓↓↓↓↓↓↓
(setq
WMI (vlax-create-object "WbemScripting.SWbemLocator")
meth1 (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil)
meth2 (vlax-invoke meth1 'ExecQuery "Select * from Win32_LogicalDisk Where DriveType = 2" nil nil nil)
meth3 (vlax-invoke meth1 'ExecQuery "Select * from Win32_DiskDrive Where InterfaceType = 'USB'" nil nil nil)
)
;;获取盘符 Name DeviceID
(setq lst nil)
(vlax-for n meth2
(setq lst (cons (substr (vlax-get n 'Name) 1 1) lst))
)
(setq lst1 nil)
(vlax-for n meth3
(setq lst1
(cons
(list
(vlax-get n 'Index)
(car (reverse (BF-str->lst (vlax-get n 'PNPDeviceID) "\\")))
)
lst1
)
)
)
(foreach obj (list WMI meth1 meth2 meth3) (if obj (vlax-release-object obj)))
(setq lst (vl-sort lst '<) lst1 (bf-LIST-SORT lst1 '<) n 0)
(repeat (length lst)
(setq uplst (cons (list (nth n lst) (strcat "UP" (substr (sernumConfused (cadr (nth n lst1))) 1 16))) uplst))
(setq n (1+ n))
(PRINC lst1)
)
(foreach x pclst (if (= (car x) "C") (setq pflst (append (list (list "PC" (cadr x))) (reverse uplst)))));盘符表
)
PNPDevideID是系统给的,不是硬件自带的,所以换系统肯定会变。
页:
[1]