Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Listar las memorias usb conectadas (https://www.clubdelphi.com/foros/showthread.php?t=80449)

seoane 08-06-2006 17:04:25

Listar las memorias usb conectadas
 
Esta funcion crea una lista con los dispositivos de almacenamiento USB conectados al equipo, en cada linea de la lista se puede leer la identificacion del vendedor, la del producto y el numero de serie (el grabado en fabrica)

Código Delphi [-]
uses Registry;

procedure ListarUSB(Lista: TStringList);
var
  i: integer;
begin
  with TRegistry.Create do
  try
    RootKey:= HKEY_LOCAL_MACHINE;
    if OpenKey('\SYSTEM\CurrentControlSet\Services\USBSTOR\Enum',FALSE) then
    begin
      i:= 0;
      while ValueExists(IntToStr(i)) do
      begin
        Lista.Add(ReadString(IntToStr(i)));
        inc(i);
      end;
      CloseKey;
    end;
  finally
    Free;
  end;
end;


Ejemplo de uso:
Código Delphi [-]
var
  Lista: TstringList;
  i: Integer;
begin
  Lista:= TStringList.Create;
  try
    ListarUSB(Lista);
    for i:= 0 to Lista.Count-1 do
      ShowMessage(Lista[ i ]);
  finally
    Lista.Free;
  end;
end;


Posibles usos, utilizar una meoria usb como llave hardware en uno de nuestros programas. Eso lo dejo para un truco diferente ...


La franja horaria es GMT +2. Ahora son las 18:40:38.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi