Jump to content

hard serial number error! w


Recommended Posts

Posted
(progn
						       ;(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)
  )
 (alert ser)
  ser
 

)

whats the wrong with my code
my autocad version is 2007https://i.postimg.cc/SxLnJNZ7/photo-2023-12-26-22-55-39.jpg

photo_2023-12-26_22-55-39.jpg

Posted (edited)

works for me too... maybe add (vl-load-com) at start of routine or try higher AutoCad version?

 

you can try this

(vl-load-com)
(cond
  ((not (setq wmi (vlax-create-object "WbemScripting.SWbemLocator")))
   (alert "Unable to set wmi"))
  ((not (setq srv (vlax-invoke wmi 'connectserver nil nil nil nil nil nil nil nil)))
   (alert "Unable to set srv"))
  ((not (setq drv (vlax-invoke srv 'execquery "Select SerialNumber from Win32_DiskDrive")))
   (alert "unable to set drv"))
  (t
   (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))
   (alert (vl-princ-to-string ser))
 )
)

 

Edited by rlx
Posted

Works for me too.

Maybe you can use vl-bt to find the problem by adding an error function.

(defun *error* (st)
  (vl-bt)
)

 

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...