sharpooth Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted May 13, 2010 Share Posted May 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
JohnM Posted May 13, 2010 Share Posted May 13, 2010 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] Quote Link to comment Share on other sites More sharing options...
sharpooth Posted May 13, 2010 Author Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
sharpooth Posted May 13, 2010 Author Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 how to use this DOSLIB?....... DosLib Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 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) Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 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" Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 I'm not sure why it would return nil... perhaps another guru can pitch in... 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) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 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" Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 That will just be down to the size allocated for the serial number Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
JohnM Posted May 13, 2010 Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 You can use it to query a local machine Quote Link to comment Share on other sites More sharing options...
JohnM Posted May 13, 2010 Share Posted May 13, 2010 i have a RAID setup do you think that is why i get a nill? alanjt do you have a RAID setup? Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2010 Share Posted May 13, 2010 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) Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 13, 2010 Share Posted May 13, 2010 This may be slower but should perhaps yield a result: Just nil...... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.