Jump to content

How to get serial number of hard drive by lisp?


nataca

Recommended Posts

3 minutes ago, mohammadreza said:

 I used this code but show me this👇
 

baseboardserial.png

@mohammadreza All you did was load the file. You have to type (get_baseboardserialnumber) with the parenthesis at the command line to RUN the function.

 

I suggest you start learning about the basics of AutoLISP / Visual LISP and customization. Look at some tutorials on Autodesk help, YouTube or google "AutoLISP programming basics" to get you started. Also check out some of LeeMac's tutorials:

http://www.lee-mac.com/tutorials.html#lisptutorials

  • Like 1
Link to comment
Share on other sites

Add last line to code

 

(princ (strcat "\nThe SerialNumber is: " SerialNumber))
)
(setq ser (GET_BASEBOARDSERIALNUMBER))

 

Are you looking at using the serialnumber as part of a security check ? You will need to compile to FAS at least.

Edited by BIGAL
Link to comment
Share on other sites

  • 3 months later...
(setq sn (dos_serialno (nth driveindex (vl-finddrive))))

this line gives me errors, sometime it's  'bad argument type: numberp: nil' and sometimes that function dos_serailno is not defined

Link to comment
Share on other sites

I think that (dos_serialno) needs drive letters as arguments... Your syntax is complex, or I am missing something...

Look at picture from documentation :

 

dos_serialno.png

Link to comment
Share on other sites

I didn't write this lisp, I'm nowhere that capable, just wanted to see how it works, but that line keeps returning error... Do I need that doslib library to put somewhere?

Link to comment
Share on other sites

Try this

; drive type 1 is a usb 2 hard disk
(defun UsbDriveSerialNumber ( / fso dr)
  (setq fso (vlax-create-object "Scripting.FileSystemObject"))
  (vlax-for d (vlax-get fso 'Drives)
    (if
	  (= (Vlax-get  d 'DriveType) 2)
      (setq dr (cons (list (vla-get-path d) (vla-get-SerialNumber d)) dr)
      )
    )
  )
  (vlax-release-object fso)
  (reverse dr)
)
(UsbDriveSerialNumber)

 

  • Like 1
Link to comment
Share on other sites

thank you, i've replaced that vl-findrive and driveindex part with yours code and some editing and now it works, but wondering how come there are no letters in hd serial, and even c drive has negative number?

Link to comment
Share on other sites

Tomislav, the serial number can be obtained in decimal or hexadecimal format. And it can be negative.

  • Like 1
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...