Lenguaje de programación Borland Delphi
Este programa obtiene el número de serie de una unidad de almacenamiento (disco duro, disco flexible, CD-ROM, DVD-ROM, ...) previamente seleccionada. Para ello necesitaremos un formulario, un botón (TButton) con el nombre "bNumeroSerie", un cuadro de lista (TListBox) con el nombre "txtUnidad" y con los Items: A, B, C, D,... hasta la Z. El código fuente completo:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
bNumeroSerie: TButton;
txtUnidad: TComboBox;
Label1: TLabel;
procedure bNumeroSerieClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//Devuelve el Número de serie del HD (disco duro)
Function CompHD (Unidad : string) : string;
Var
VolumeNameBuffer : array [0..MAX_PATH] of Char;
VolumeSerialNumber : DWord;
MaximumComponentLength : DWord;
FileSystemFlags : DWord;
Begin
GetVolumeInformation( pchar(Unidad),VolumeNameBuffer,
DWORD(sizeof(VolumeNameBuffer)),@VolumeSerialNumber,
MaximumComponentLength,FileSystemFlags,nil,0);
result := IntToHEX(VolumeSerialNumber,8);
End;
procedure TForm1.bNumeroSerieClick(Sender: TObject);
begin
ShowMessage('El número de serie es: ' +
CompHD(txtUnidad.Text + ':\'));
end;
end.
Publicado el: 2004-05-23