明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2880|回复: 11

关于物理硬盘序列号

[复制链接]
发表于 2008-10-13 15:34:00 | 显示全部楼层 |阅读模式

为什么在WIN2000下不能使用方法 VLAX-METHOD 'CONNECTSERVER

请高手赐教

(defun phyhar (/ ret serx objw lccon lox)
  (vl-load-com)
  (setq serx '())
  (if (SETQ OBJW (VLAX-CREATE-OBJECT "wbemScripting.SwbemLocator"))
    (progn
      (SETQ lccon (VLAX-INVOKE
    OBJW       'ConnectServer      "."
    "\\root\\cimv2"   ""      ""
    ""        ""   128      nil
   )
      )
      (setq lox (vlax-invoke
  lccon
  'ExecQuery
  "Select SerialNumber,Tag from Win32_PhysicalMedia"
)
      )
      (vlax-for item lox
(setq serx (cons (list (vlax-get item 'Tag)
       (vlax-get
item
'SerialNumber
       )
)
serx
   )
)
      )
      (vlax-release-object lox)
      (vlax-release-object lccon)
      (vlax-release-object objW)
    )
  )
  (princ (reverse serx))
  (princ)
)

发表于 2022-5-2 13:36:46 | 显示全部楼层
(DEFUN WMIGETSREENRESOLUTION (/ ITEM METH1 METH2 S ITEMS WMI HR)
  (VL-LOAD-COM)
  (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_VideoController")
        HR (VLAX-FOR ITEM METH2
          (SETQ ITEMS (LIST (VLAX-GET ITEM 'CURRENTHORIZONTALRESOLUTION)
            (VLAX-GET ITEM 'CURRENTVERTICALRESOLUTION ))))
  )
  (VLAX-RELEASE-OBJECT METH1)
  (VLAX-RELEASE-OBJECT METH2)
  (VLAX-RELEASE-OBJECT WMI)
  HR
)
;;;
(defun WmiGetOsSerialNumber (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 SerialNumber from Win32_OperatingSystem")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'SerialNumber))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun WmiGetOsCaption (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 Caption from Win32_OperatingSystem")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'Caption))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun WmiTotalPhysicalMemory (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 TotalPhysicalMemory from Win32_LogicalMemoryConfiguration")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'TotalPhysicalMemory))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (strcat (itoa (fix (/ (car s) 1024))) " Mbytes")
)
;;;
(defun wmiMaxClockSpeed (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 MaxClockSpeed from Win32_Processor")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'MaxClockSpeed))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (strcat (itoa (car s)) " MHz")
)
;;;
(defun wmiProcessorType (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 Name from Win32_Processor")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'Name))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun wmiProcessorType2 (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 DataWidth from Win32_Processor")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'DataWidth))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
;;;
(defun wmiProcessorType3 (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 Architecture from Win32_Processor")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'Architecture))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)
发表于 2022-5-2 12:04:58 | 显示全部楼层
本帖最后由 baitang36 于 2022-5-2 12:06 编辑

win10下试验是成功的。如果有多块硬盘,楼主的代码只能返回最后一块硬盘的物理序列号。我把它改了一下,让它返回所有硬盘物理序列号表。

(defun HDSerial        (/ wmi srv drv ser)
  (SETQ SER NIL)
  (vl-catch-all-apply
    (function
      (lambda ()
        (if
          (setq        wmi (vlax-create-object "WbemScripting.SWbemLocator")
                srv (vlax-invoke
                      wmi      'connectserver         nil          nil
                      nil      nil        nil         nil          nil
                      nil
                     ) ;_ vlax-invoke
                drv (vlax-invoke
                      srv
                      'execquery
                      "Select SerialNumber from Win32_DiskDrive"
                    ) ;_ vlax-invoke
          ) ;_ setq
           (vlax-for item drv
             (vlax-for prop (vlax-get item 'Properties_)
               (if (eq "SERIALNUMBER" (strcase (vlax-get prop 'name)))
                 (setq ser
                        (CONS (vl-string-trim " " (vlax-get prop 'value))
                              SER
                        ) ;_ CONS
                 ) ;_ setq
               ) ;_ if
             ) ;_ vlax-for
           ) ;_ vlax-for
        ) ;_ if
      ) ;_ lambda
    ) ;_ function
  ) ;_ vl-catch-all-apply
  (if drv
    (vlax-release-object drv)
  ) ;_ if
  (if srv
    (vlax-release-object srv)
  ) ;_ if
  (if wmi
    (vlax-release-object wmi)
  ) ;_ if
  (REVERSE ser)
) ;_ defun


发表于 2022-5-2 13:38:09 | 显示全部楼层
(defun MainBoardSerial (/ item meth1 meth2 s serx wmi)
  (vl-load-com)
  (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 SerialNumber from Win32_BaseBoard")
        s (vlax-for item meth2 (setq serx (list (vlax-get item 'SerialNumber))))
  )
  (vlax-release-object meth1)
  (vlax-release-object meth2)
  (vlax-release-object wmi)
  (car s)
)


(vl-load-com)
(defun GetMacAddress
       (/ LocatorObj ServiceObj SecurityObj ObjectSetObj OutList)
  (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
  (setq
    ServiceObj (vlax-invoke LocatorObj 'ConnectServer nil nil nil nil nil nil nil nil)
  )
  (setq        ObjectSetObj
        (vlax-invoke ServiceObj 'ExecQuery "Select * from Win32_NetworkAdapter")
  )
  (vlax-for Obj        ObjectSetObj
    (if        (wcmatch (vl-princ-to-string (vlax-get Obj 'AdapterType)) "Ethernet 802.*")
      (setq OutList (cons (vlax-get Obj 'MACAddress) OutList))
    )
  )
  (foreach Obj (list LocatorObj ServiceObj SecurityObj ObjectSetObj)
    (and Obj (vlax-release-object Obj))
  )
  OutList
)
发表于 2011-8-5 15:09:14 | 显示全部楼层
返回值是nil,
发表于 2011-8-12 08:36:47 | 显示全部楼层
加密要加到硬件的地步了....................
发表于 2022-5-4 18:21:05 来自手机 | 显示全部楼层
好帖子  可以绑定硬盘不再怕格式化硬盘会变机器码了
发表于 2022-6-19 12:26:06 | 显示全部楼层
很好的帖子
发表于 2022-7-4 14:48:49 | 显示全部楼层
baitang36 发表于 2022-5-2 12:04
win10下试验是成功的。如果有多块硬盘,楼主的代码只能返回最后一块硬盘的物理序列号。我把它改了一下,让 ...

包含移动硬盘和U盘吗
发表于 2022-7-5 07:51:55 | 显示全部楼层
烟盒迷唇 发表于 2022-7-4 14:48
包含移动硬盘和U盘吗

你试验一下啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-15 09:30 , Processed in 0.193156 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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