Jump to content

vlax-create-object ???


sharpooth

Recommended Posts

Hello guys,

 

1.How can i understand which classes are available to put in:

 

(vlax-create-object "WbemScripting.SWbemLocator" )

(vlax-create-object "Scripting.FileSystemObject" )

....

and so on

 

2. Is there way to get a REAL hard disk number?

 

 

 

Thanks

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • alanjt

    10

  • sharpooth

    6

  • JohnM

    3

Top Posters In This Topic

 

2. Is there way to get a REAL hard disk number?

 

 

 

Thanks

 

Do you mean the serial number of a hard disk?

If so, using the (dos_serialno) of DOSLIB is one option.

Link to comment
Share on other sites

Try this

Call it and pass it a drive letter like “C”

Note: drive serial numbers are assigned by the operating system so if you reformat a drive the serial number will be different.

 

[font=Times New Roman][font=Times New Roman](defun VxGetDriveInfos (Drv / DrvObj FilSys RetVal) [/font]
[font=Times New Roman](setq FilSys (vlax-create-object "Scripting.FileSystemObject") [/font]
[font=Times New Roman]      RetVal (cond [/font]
[font=Times New Roman]              ((= (vlax-invoke FilSys "DriveExists" Drv) 0) 0) [/font]
[font=Times New Roman]              ((setq DrvObj (vlax-invoke FilSys "GetDrive" Drv)) [/font]
[font=Times New Roman]               (cond [/font]
[font=Times New Roman]                ((= (vlax-get DrvObj "IsReady") 0) -1) [/font]
[font=Times New Roman]                ((list [/font]
[font=Times New Roman]                  (/(vlax-get DrvObj "TotalSize") 1000.0) [/font]
[font=Times New Roman]                  (/(vlax-get DrvObj "FreeSpace") 1000.0) [/font]
[font=Times New Roman]                  (vlax-get DrvObj "DriveType") [/font]
[font=Times New Roman]                  (vlax-get DrvObj "FileSystem") [/font]
[font=Times New Roman]                  (vlax-get DrvObj "SerialNumber") [/font]
[font=Times New Roman]                  (vlax-get DrvObj "ShareName") [/font]
[font=Times New Roman]                  (vlax-get DrvObj "VolumeName") [/font]
[font=Times New Roman]                 ) [/font]
[font=Times New Roman]                ) [/font]
[font=Times New Roman]               ) [/font]
[font=Times New Roman]              ) [/font]
[font=Times New Roman]             ) [/font]
[font=Times New Roman]) [/font]
[font=Times New Roman](if DrvObj (vlax-release-object DrvObj)) [/font]
[font=Times New Roman](vlax-release-object FilSys)  [/font]
[font=Times New Roman]RetVal [/font]
[font=Times New Roman]) [/font]
[/font]

Link to comment
Share on other sites

When i am using the next code

 

(setq bbb (vlax-get-property (vlax-invoke (vlax-create-object "Scripting.FileSystemObject") 'Getdrive "c:") "SerialNumber" ))

 

I am receiving "142782703", but this is not the correct SerNum of HDD

 

:(

Link to comment
Share on other sites

Do you mean the serial number of a hard disk?

If so, using the (dos_serialno) of DOSLIB is one option.

 

how to use this DOSLIB?

Link to comment
Share on other sites

Another:

 

(defun DiskDriveSerial (/ WMI Serv DiskD item prop ser)
 (vl-load-com)
 ;; Lee Mac  ~  13.05.10
 
 (setq WMI    (vlax-create-object "WbemScripting.SWbemLocator")
       Serv   (vlax-invoke WMI  'ConnectServer nil nil nil nil nil nil nil nil)
       DiskD  (vlax-invoke Serv 'ExecQuery "Select SerialNumber from Win32_DiskDrive"))
       
 (vlax-for item DiskD
   (vlax-for prop (vlax-get item 'Properties_)
     (if (eq "SerialNumber" (vlax-get prop 'Name))
       (setq ser (vlax-get prop 'Value))
     )
   )
 )

 (mapcar 'vlax-release-object (list DiskD Serv wmi))
 
 ser)

Link to comment
Share on other sites

Lee, your submission returns nil for me. I wonder if it has to do with you running Vista.

 

Here's one I scratched out that uses basically the same method as the above posted one.

 

(defun DriveSerial (drive / *error* sys serial drive)
 ;; Get specified drive's serial number
 ;; drive - string of drive in question (eg. "c:" or "c")
 (defun *error* (m)
   (mapcar
     (function (lambda (x) (vl-catch-all-apply (function vlax-release-object) (list x))))
     (list drive sys)
   )
 )

 (if (setq sys (vlax-create-object "Scripting.FileSystemObject"))
   (setq serial (vlax-get (setq drive (vlax-invoke sys 'GetDrive drive)) 'SerialNumber))
 )
 (*error* nil)
 serial
)

I'm curious if yours returns the same as this one on your machine.

 

Another strange thing is, what I posted returns a different number than what DosLib returns.

eg.

Command: (driveserial "c")
150345461
Command: (dos_serialno "c")
"08F616F5"

Link to comment
Share on other sites

I'm not sure why it would return nil... perhaps another guru can pitch in... o:)

 

As for your other query - bear in mind that the SerialNumber property of the DriveObject will return in Decimal, perhaps DosLib returns in Hex?

 

(defun DiskDriveSerial ( Drv / toBase Scr ser )

 (defun toBase ( str from to / -> <- toChar )
   ;; Lee Mac  ~  01.05.10

   (defun -> ( n / b x )
     (if (<= to n)
       (strcat (-> (/ n to)) (-> (rem n to)))
       (toChar n)
     )
   )

   (defun <- ( l )
     (if l
       (+ (* from (<- (cdr l))) (car l)) 0
     )
   )

   (defun toChar ( n ) (chr (+ n (if (< n 10) 48 55))))

   (->
     (<-
       (mapcar
         (function
           (lambda ( x )
             (- x (if (< x 58) 48 55))
           )
         )
         (reverse
           (vl-string->list str)
         )
       )
     )
   )
 )
 
 (setq Scr (vlax-create-object "Scripting.FileSystemObject")
       ser (vlax-get (vlax-invoke Scr 'Getdrive Drv) 'SerialNumber))

 (vlax-release-object Scr)

 (toBase (vl-princ-to-string ser) 10 16)
)

Link to comment
Share on other sites

 

As for your other query - bear in mind that the SerialNumber property of the DriveObject will return in Decimal, perhaps DosLib returns in Hex?

 

Excellent point, I wasn't thinking about HEX.

 

Only a difference of a leading zero.

 

Command: (diskdriveserial "C")
"8F616F5"

Command: (dos_serialno "c")
"08F616F5"

Link to comment
Share on other sites

YOu didn't answer my question. On your machine, did the example I posted return the same value as the return from your original submission?

Link to comment
Share on other sites

No it doesn't, but they are two different things I believe.

 

The Serial Number returned through the Windows Management Instrumentation is the Serial given by the Manufacturer,

eg. WD-WM3493798728

Link to comment
Share on other sites

No it doesn't, but they are two different things I believe.

 

The Serial Number returned through the Windows Management Instrumentation is the Serial given by the Manufacturer,

eg. WD-WM3493798728

 

Sounds like a pretty good idea to me. I still wonder why I can't get yours to work on mine (XP machine). I wonder if someone else can get an actual result with it. Out of curiosity, would you have to change out 32 for 64 if the bit of the machine was different or would it be completely different all together?

 

Seems like there's just more consistency in the other method.

 

on my machine...

Command: (setq WMI    (vlax-create-object "WbemScripting.SWbemLocator")
(_>         Serv   (vlax-invoke WMI  'ConnectServer nil nil nil nil nil nil nil 
nil)
(_>         DiskD  (vlax-invoke Serv 'ExecQuery "Select SerialNumber from 
Win32_DiskDrive"))
#<VLA-OBJECT ISWbemObjectSet 0151f068>

Command: (at:dump diskd)
; ISWbemObjectSet: A collection of Classes or Instances
; Property values:
;   Count (RO) = SWbemObjectSet: Invalid query
;   Security_ (RO) = #<VLA-OBJECT ISWbemSecurity 0151f0c8>
; Methods supported:
;   Item (2)
nil

Command: (vlax-for d diskd (setq dlst (cons d dlst)))
nil

Link to comment
Share on other sites

Lee,

I tried your first example and also got a nill response.

I don’t know a lot about WMI but isn’t if for looking across servers?

Are you connected to a server?

Link to comment
Share on other sites

i have a RAID setup do you think that is why i get a nill?

alanjt do you have a RAID setup?

 

Nope, just one HDD.

Link to comment
Share on other sites

This may be slower but should perhaps yield a result:

 

(defun DiskDriveSerial (/ WMI Serv DiskD item prop ser)
 (vl-load-com)
 ;; Lee Mac  ~  13.05.10
 
 (setq WMI    (vlax-create-object "WbemScripting.SWbemLocator")
       Serv   (vlax-invoke WMI  'ConnectServer nil nil nil nil nil nil nil nil)
       DiskD  (vlax-invoke Serv 'ExecQuery "Select * from Win32_DiskDrive"))
       
 (vlax-for item DiskD
   (vlax-for prop (vlax-get item 'Properties_)
     (if (eq "SerialNumber" (vlax-get prop 'Name))
       (setq ser (vlax-get prop 'Value))
     )
   )
 )

 (mapcar 'vlax-release-object (list DiskD Serv wmi))
 
 ser)

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