Jump to content

How to get serial number of hard drive by lisp?


Recommended Posts

Please try,

(vl-load-com)
(vlax-dump-Object (vlax-invoke (vlax-create-object "Scripting.FileSystemObject") 'getdrive "c:")t)

Link to post
Share on other sites
;;;                                                  				*
;;; PART OF 'ASMILIB' LIBRUARY  						*
;;; Created: 07.10.2007         						*
;;; Last modyfied: 07.10.2007   						*
;;; © Alexanders Smirnovs (ASMI)						*
;;;                                                  				*


;;; *********************************
;;; **** PC Hardware Functions ******
;;; *********************************


;;;                                                  				*
;;; Retrieves Hard Drive serial number                         		        *
;;;                                                  				*
;;; Arguments:                                       				*
;;; 		Path - Path of Hard Drive, for example "C:" (string)		*
;;;                                                  				*
;;; Output:                                          				*
;;;		Hard Drive serial number (integer) or NIL in case of error. 	*
;;;                                                  				*


(defun #Asmi_Get_Drive_Serial(Path / fsObj hSn abPth cDrv)
 (vl-load-com)
 (if
   (and
     (setq fsObj(vlax-create-object "Scripting.FileSystemObject"))
     (not
(vl-catch-all-error-p
  (setq abPth(vl-catch-all-apply 'vlax-invoke-method
	       (list fsObj 'GetAbsolutePathName Path))
	       ); end setq
	   ); end vl-catch-all-error-p
	); end not
  ); end and
   (progn
     (setq cDrv(vlax-invoke-method fsObj 'GetDrive
       (vlax-invoke-method fsObj 'GetDriveName abPth
       ); end vlax-invoke-method
     );end vlax-invoke-method
    ); end setq
    (if
      (vl-catch-all-error-p
  (setq hSn(vl-catch-all-apply 'vlax-get-property
    (list cDrv 'SerialNumber))))
    (progn
      (vlax-release-object cDrv)
      (setq hSn nil)
    ); end progn
      ); end if
   (vlax-release-object fsObj)
   ); end progn
  ); end if
 hSn
 ); end of #Asmi_Get_Drive_Serial

Link to post
Share on other sites
  • 9 years later...
Great !!! thanks. Can I get serial number of Mainboad, VGA, ...?

 

(defun Get_BaseBoardSerialNumber (/ LocatorObj ServiceObj ObjectSetObj SerialNumber)
 (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_BaseBoard"
        )
 )
 (vlax-for Obj ObjectSetObj
   (setq SerialNumber
          (vlax-get Obj 'SerialNumber)
   )
 )
 (foreach Obj
              (list LocatorObj ServiceObj ObjectSetObj)
   (and Obj (vlax-release-object Obj))
 )
 SerialNumber
)

Link to post
Share on other sites
(defun Get_ProcessorId (/               LocatorObj      SecurityObj
                       SecurityObj     ObjectSetObj    Processor_Id
                      )
 (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_Processor"
        )
 )
 (vlax-for Obj ObjectSetObj
   (setq Processor_Id
          (vlax-get Obj 'ProcessorId)
   )
 )
 (foreach Obj
              (list LocatorObj ServiceObj SecurityObj ObjectSetObj)
   (and Obj (vlax-release-object Obj))
 )
 Processor_Id
)

Link to post
Share on other sites
(defun Get_UUID (/ LocatorObj ServiceObj ObjectSetObj UUID)
 (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 UUID FROM Win32_ComputerSystemProduct"
        )
 )
 (vlax-for Obj ObjectSetObj
   (setq UUID
          (vlax-get Obj 'UUID)
   )
 )
 (foreach Obj
              (list LocatorObj ServiceObj ObjectSetObj)
   (and Obj (vlax-release-object Obj))
 )
 UUID
)

Link to post
Share on other sites
(defun c:SerialInfo_ BIOS(/ WMI meth1 meth2 serial)
(vl-load-com)
(cond ((and (setq WMI (vlax-create-object "WbemScripting.SWbemLocator"))
(setq meth1 (vlax-invoke WMI 'ConnectServer nil nil nil nil nil nil nil nil))
(setq meth2 (vlax-invoke meth1 'ExecQuery (strcat "Select * from Win32_" "BIOS")))
(vlax-for itm (vlax-get (vlax-invoke meth2 'ItemIndex 0) 'Properties_)
(if (eq (vlax-get itm 'name) "SerialNumber")
(setq serial (vlax-get itm 'value)))))))
(mapcar 'vlax-release-object (list meth1 meth2 wmi))
serial)

Link to post
Share on other sites
(defun get_macaddress  (/ Locator Server Query ret)
 (if (and (setq Locator (vlax-create-object "WbemScripting.SWbemLocator"))
          (setq Server (vlax-invoke Locator 'ConnectServer "." "root\\cimv2"))
          (setq Query (vlax-invoke Server 'ExecQuery "select * from Win32_NetworkAdapterConfiguration where IPEnabled = True")))
   (vlax-for item Query (setq ret (vlax-get item 'MacAddress))))
 (foreach obj '(Locator Server Query)
   (vl-catch-all-apply 'vlax-release-object (list obj)))
 ret)

Link to post
Share on other sites

Nice one dilan! Now I'm realising that SQL can be used in lisp.. :cool:

And a little remark:

use

(foreach obj (list Locator Server Query) ...

instead of

(foreach obj '(Locator Server Query) ...

 

to release the actual objects and not the symbols that are holding the variables for the objects.

Link to post
Share on other sites
Nice one dilan! Now I'm realising that SQL can be used in lisp.. :cool:

And a little remark:

use

(foreach obj (list Locator Server Query) ...

instead of

(foreach obj '(Locator Server Query) ...

 

to release the actual objects and not the symbols that are holding the variables for the objects.

 

 

good catch , missed that one in the last function.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...