How many Pendrive

How many Pendrive

Anonymous
Not applicable
1,011 Views
6 Replies
Message 1 of 7

How many Pendrive

Anonymous
Not applicable

I want to know through lisp how many pendrive are connected to the pc.

To go through each one and read its physical direction.

Is this possible with lisp?

 

thanks...

 

 

 

0 Likes
1,012 Views
6 Replies
Replies (6)
Message 2 of 7

Scottu2
Advocate
Advocate

jose.diaz.montejo, you could have a lisp routine to test writing a file to the specified drive (usb drive).  If it fails then either it does not exist or insufficient rights to access the drive, otherwise it does exist and keep track of that drive letter.

 

Is a pendrive a usb drive?

Please clarify "read its physical direction".

0 Likes
Message 3 of 7

trevor.bird.au
Advocate
Advocate

Hi Jose,

 

The following program will identify pen drives:

 

;;  PenDrives.lsp by Trevor Bird
;;
;;  2017-07-29

;;;--------------------------------------------------------------------
(defun c:pendrives
  (/
    DriveType

    IsReady

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

  (vlax-for vf::obj_Drive (vlax-get-property obj_FSO 'Drives)
    (setq IsReady   (vlax-get-property vf::obj_Drive 'IsReady)
          DriveType (vlax-get-property vf::obj_Drive 'DriveType)
    );setq

    (if (and (= IsReady :vlax-true)
             (= DriveType 1)
        );and
      (progn
        (princ "\nDrive ")
        (princ (vlax-get-property vf::obj_Drive 'DriveLetter))
        (princ ": = Removable")
      );progn
    );if
  );vf::obj_Drive

  (vlax-release-object obj_FSO)

  (princ)
);c:pendrives

 

 

Regards,

Trevor

Message 4 of 7

Anonymous
Not applicable

I have been reading that there are two identification numbers for a USB (serialnumber and Physicalmedia),
Serialnumber: if you Format the USB this changes.
PhysicalMedia: if you Format the USB does not change.

 

And I need Physicalmedia.

 

Thanks.

0 Likes
Message 5 of 7

Scottu2
Advocate
Advocate

jose,

Try the lisp routine by SonikSSV.

Run the pendrives.lsp

When there is no drive plugged into the computer it reports nothing.

If there is a pendrive plugged into the computer the program displays the drive letter.

If the pendrive was not formatted, then the program would not detected, thus report nothing.

 

Did you want see the physical media information, like 32FAT, NTFS, bytes used or bytes free?

 

 

Message 6 of 7

Anonymous
Not applicable

I have tried the routine pendrive.lsp, and I have modified it and add another one that I find.
And it gives the expected result.
Only the SerialNumber data changes if the USB is formatted.
Also read on a page that this data, can be manipulated easily, so that the user could clone the same data in several USB.
That's why I need to find the physical and irreplaceable USB serial.

 

;;Programa para ligar una unidad de almacenamiento con su serial
(defun Serial_Usb ()
(setq obj_FSO (vlax-create-object "Scripting.FileSystemObject"))
(setq set:prod 0)
(vlax-for vf::obj_Drive (vlax-get-property obj_FSO 'Drives)
	(setq IsReady   (vlax-get-property vf::obj_Drive 'IsReady)
          DriveType (vlax-get-property vf::obj_Drive 'DriveType)
    )
	(setq IsReady   (vlax-get-property vf::obj_Drive 'IsReady)
          DriveType (vlax-get-property vf::obj_Drive 'DriveType)
    )
	(setq driveL 	(vlax-get-property vf::obj_Drive 'DriveLetter))
	
	(setq physical_drive 1616258636)
	(setq getph_drive (DriveSerial (strcat driveL ":")))
	(alert (strcat driveL ":"))
	(if (= physical_drive getph_drive)
		(setq set:prod 1)
	);end if
)
);end defun

(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
)
0 Likes
Message 7 of 7

Scottu2
Advocate
Advocate

Jose,

 

Nice routine.

 

It may not be a significant problem but the variable DRIVE appears in the public and private variable definitions.

(defun DriveSerial (drive / *error* sys serial drive)

 

If the USB drive does not have a permanent ID number then i would suggest that you create a text file called DISK.ID on the USB.

 

DISK.ID file format

Line1: Serial number

Line2: Description

Line3: Date created

 

Keep track of the new numbers

Append the new serial number to a log file and

then write the DISK.ID with that new serial number to the USB.

 

Read the DISK.ID and display the lines

and check the serial number against the log file

 

 

 

 

 

 

 

0 Likes