Code Red > AutoLISP (Vanilla / Visual)

HD Serial number

(1/6) > >>

Marc'Antonio Alessi:


I'm looking for a function that gives the same result as dos_serialno, the functions I report below (sorry if I didn't report all the credits)
[/size]get three different results...
[/size]"BCA30E72" -1130164622 "50026B775203E442"


--- Code: ---
(dos_serialno "C:")            => "BCA30E72"
(#Asmi_Get_Drive_Serial "c:") => -1130164622
(UsbDriveSerialNumber) => ((("C:" -1130164622) ("G:" 428019990) ("H:" 943522054) ("Z:" -693829664)) nil)
(VxGetDriveInfos "C:") => (2.15739e+008 4.28575e+007 2 "NTFS" -1130164622 "" "OS")
(gthardware:generateid) => ("-1130164622" "ASUS01" "User1")
(HDSerial)             => "50026B775203E442"

--- End code ---





--- Code: ---; drive type 1 is a usb 2 hard disk
(defun UsbDriveSerialNumber ( / fso HrdDsk UsbDsk)
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (vlax-for d (vlax-get fso 'Drives)
    (cond
      ( (= (Vlax-get d 'DriveType) 1)
        (setq UsbDsk (cons (list (vla-get-path d) (vla-get-SerialNumber d)) UsbDsk))
      )
      ( (= (Vlax-get d 'DriveType) 2)
        (setq HrdDsk (cons (list (vla-get-path d) (vla-get-SerialNumber d)) HrdDsk))
      )
    ; ( T (print d) )
    )
  )
  (vlax-release-object fso)
  (list (reverse HrdDsk) (reverse UsbDsk))
)
;;; PART OF 'ASMILIB' LIBRUARY  *
;;; Created: 07.10.2007          *
;;; Last modyfied: 07.10.2007    *
;;; © Alexanders Smirnovs (ASMI) *
(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


(defun HDSerial ( / wmi srv drv ser )
  (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)
                drv (vlax-invoke srv 'execquery "Select SerialNumber from Win32_DiskDrive")
          )
          (vlax-for item drv
            (vlax-for prop (vlax-get item 'Properties_)
              (if (eq "SERIALNUMBER" (strcase (vlax-get prop 'name)))
                (setq ser (vl-string-trim " " (vlax-get prop 'value)))
              )
            )
          )
        )
      )
    )
  )
  (if drv (vlax-release-object drv))
  (if srv (vlax-release-object srv))
  (if wmi (vlax-release-object wmi))
  ser
)


(DEFUN gthardware:generateid (/ filesystemobject drives n serial wscript pcname pcuser)
  (SETQ serial 0
                pcname ""
                pcuser ""
  )
  (COND ((SETQ wscript (VLAX-CREATE-OBJECT "WScript.Network"))
                 (SETQ pcname (VLAX-GET-PROPERTY wscript "ComputerName") ; Computer Name
                           pcuser (VLAX-GET-PROPERTY wscript "UserName") ; UserName
                 )
                 (VLAX-RELEASE-OBJECT wscript)
                 ;; Obtain the first Hard drive serial number
                 (COND ((SETQ filesystemobject (VLAX-CREATE-OBJECT "Scripting.FilesystemObject"))
                                ;; access the Drives collection
                                (SETQ drives (VLAX-GET-PROPERTY filesystemobject 'drives))
                                ;; Check each drive for a fixed drive. When the first drive is found, exit.
                                (VL-CATCH-ALL-APPLY
                                  '(LAMBDA ()
                                         (VLAX-FOR n drives
                                           ;;If there drive is a fixed drive, get the serial and exit
                                           (IF (= (VLAX-GET-PROPERTY n 'drivetype) 2)
                                                 (PROGN
                                                   (SETQ serial (VLAX-GET-PROPERTY n 'serialnumber))
                                                   (EXIT)
                                                 )
                                           )
                                         )
                                   )
                                )
                                ;; Release the vla objects
                                (VLAX-RELEASE-OBJECT drives)
                                (VLAX-RELEASE-OBJECT filesystemobject)
                           )
                 )
                )
  )
  (list (ITOA serial) pcname pcuser)
)


; Copyright: ©2001 MENZI ENGINEERING GmbH, Switzerland
;
(defun VxGetDriveInfos (Drv / DrvObj FilSys RetVal)
 (vl-load-com)
 (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
       RetVal (cond
               ((= (vlax-invoke FilSys 'DriveExists Drv) 0) 0)
               ((setq DrvObj (vlax-invoke FilSys 'GetDrive Drv))
                (cond
                 ((= (vlax-get DrvObj 'IsReady) 0) -1)
                 ((list
                   (/ (vlax-get DrvObj 'TotalSize) 1000.0)
                   (/ (vlax-get DrvObj 'FreeSpace) 1000.0)
                   (vlax-get DrvObj 'DriveType)
                   (vlax-get DrvObj 'FileSystem)
                   (vlax-get DrvObj 'SerialNumber)
                   (vlax-get DrvObj 'ShareName)
                   (vlax-get DrvObj 'VolumeName)
                  )
                 )
                )
               )
              )
 )
 (if DrvObj (vlax-release-object DrvObj))
 (vlax-release-object FilSys)
 RetVal
)
--- End code ---

d2010:
Why you need, the serial number  of-HDD?
You, do insert more crashes inside  AutoCad?   
Perhaps you block the programs.fas, forced to operating system win11?

 :thinking:

VovKa:
works on win7
not sure about others

--- Code: ---(defun vk_GetWbem (NameSpace Class Props / LocatorObj ServiceObj ObjectSetObj OutList)
  (and (setq LocatorObj (vlax-create-object "WbemScripting.SWbemLocator"))
       (setq ServiceObj (vlax-invoke-method LocatorObj 'ConnectServer "." NameSpace nil nil nil nil nil nil))
       (setq ObjectSetObj (vlax-invoke-method ServiceObj 'ExecQuery (strcat "SELECT * FROM " Class) nil nil nil))
       (vlax-for Obj ObjectSetObj
(setq OutList (cons (mapcar (function (lambda (p) (cons p (vlax-get Obj p)))) Props)
     OutList
       )
)
       )
  )
  (vk_ReleaseObjects (list ObjectSetObj ServiceObj LocatorObj))
  (reverse OutList)
)
(defun vk_GetHDDID (/)
  (mapcar 'list
  (mapcar 'cdar (vk_GetWbem "root\\cimv2" "Win32_DiskDrive" (list "Model")))
  (mapcar 'cdar (vk_GetWbem "root\\cimv2" "Win32_PhysicalMedia" (list "SerialNumber")))
  )
)

--- End code ---

Marc'Antonio Alessi:

--- Quote from: VovKa on February 03, 2023, 05:27:17 AM ---works on win7
not sure about others

--- Code: --- ...
--- End code ---

--- End quote ---

--- Code: ---Thanks VovKa :
; errore: no function definition: VK_RELEASEOBJECTS
--- End code ---

VovKa:

--- Quote from: Marc'Antonio Alessi on February 03, 2023, 05:39:43 AM ---
--- Code: ---Thanks VovKa :
; errore: no function definition: VK_RELEASEOBJECTS
--- End code ---

--- End quote ---
nothing special, just substitute it with (mapcar 'vlax-release-object ... )

Navigation

[0] Message Index

[#] Next page

Go to full version