Author Topic: Function to get hard drive serial number  (Read 5632 times)

0 Members and 1 Guest are viewing this topic.

laidbacklarry

  • Guest
Function to get hard drive serial number
« on: May 28, 2011, 11:20:07 AM »
Is there an ACAD equivalent for Bricscad (get_diskserialid)?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16894
  • Superior Stupidity at its best
Re: Function to get hard drive serial number
« Reply #1 on: May 28, 2011, 11:27:31 AM »
I don't think so, but there is the ability to use scripting to get the serial number. There was an example somewhere within these forums. I'll see if I can find it.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12605
  • London, England
Re: Function to get hard drive serial number
« Reply #2 on: May 28, 2011, 11:30:20 AM »
Perhaps?

Code: [Select]
(defun HDSerial ( drive / fso drv ser )
  (vl-catch-all-apply
    (function
      (lambda nil
        (setq fso (vlax-create-object "Scripting.FileSystemObject")
              drv (vlax-invoke-method fso 'getdrive drive)
              ser (vlax-get-property drv 'serialnumber)
        )
      )
    )
  )
  (if drv (vlax-release-object drv))
  (if fso (vlax-release-object fso))
  ser
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16894
  • Superior Stupidity at its best
Re: Function to get hard drive serial number
« Reply #3 on: May 28, 2011, 11:35:35 AM »
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Lee Mac

  • Seagull
  • Posts: 12605
  • London, England
Re: Function to get hard drive serial number
« Reply #4 on: May 28, 2011, 11:47:38 AM »
Another, but I think this method only works on Vista OS onwards:

Code: [Select]
(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
)

laidbacklarry

  • Guest
Re: Function to get hard drive serial number
« Reply #5 on: May 28, 2011, 05:47:51 PM »
Keith, Lee Mac - Thanks. I'll start testing these to see what works best. Our user base ranges from XP thru Windows7, so I may have to test for OS platform to decide which to use. But, thanks again.

Lee Mac

  • Seagull
  • Posts: 12605
  • London, England
Re: Function to get hard drive serial number
« Reply #6 on: May 28, 2011, 05:55:18 PM »
Keith, Lee Mac - Thanks. I'll start testing these to see what works best. Our user base ranges from XP thru Windows7, so I may have to test for OS platform to decide which to use. But, thanks again.

You're welcome :-)

If available to you, another option would be to use DosLib's dos_serialno function (will return the same as the function utilising the FSO method).

Also, bear in mind that the function I posted using WMI will return the serial number allocated by the manufacturer, which is different from the serial assigned to a disk volume as returned by the SerialNumber Property of a Drive Object.
« Last Edit: May 28, 2011, 06:07:58 PM by Lee Mac »

laidbacklarry

  • Guest
Re: Function to get hard drive serial number
« Reply #7 on: May 28, 2011, 06:07:28 PM »
Keith, Lee Mac - Thanks. I'll start testing these to see what works best. Our user base ranges from XP thru Windows7, so I may have to test for OS platform to decide which to use. But, thanks again.

You're welcome :-)

If available to you, another option would be to use DosLib's dos_serialno function.
DosLib is a great program...  we used it from its first release until about 2-1/2 years ago. Our user base stretches from Acad 2002 through 2012 and with the advent of both 32-bit and 64-bit versions of DosLib, I decided to write my own Lisp versions of the 20 or so DosLib functions we use so I could stop revising our startup routine to figure out which version of DosLib to load. And, as you may know, until recently DosLib wasn't available for Bricscad.

Lee Mac

  • Seagull
  • Posts: 12605
  • London, England
Re: Function to get hard drive serial number
« Reply #8 on: May 28, 2011, 06:08:40 PM »
Edited above  :wink: