PDA

Ver la Versión Completa : Número Id de un disco o disquete


dec
02-07-2006, 00:36:05
¿Cómo puedo obtener el nº de id de un disco o diskette?

(Obtenido de Borland)


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

uses
ShlObj, ActiveX, ComObj, Registry;

procedure TForm1.Button1Click(Sender: TObject);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
FileName : String;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
FileName := 'NOTEPAD.EXE';
with MySLink do begin
SetArguments('C:\AUTOEXEC.BAT');
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
end;
MyReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer');
// Use the next line of code to put the shortcut on your desktop
Directory := MyReg.ReadString('Shell Folders','Desktop','');
// Use the next three lines to put the shortcut on your start menu
// Directory := MyReg.ReadString('Shell Folders','Start Menu','')+
// '\Whoa!';
// CreateDir(Directory);
WFileName := Directory+'\FooBar.lnk';
MyPFile.Save(PWChar(WFileName),False);
MyReg.Free;
end;

end.



function TFCodigo.GetDiskVolSerialID(cDriveName: char): DWord;
var
dwTemp1, dwTemp2 : DWord;
begin
GetVolumeInformation(
PChar(cDriveName + ':\'),
Nil,
0,
@Result,
dwTemp2,
dwTemp2,
Nil,
0
);
end;


Donde cDriveName es la letra de la unidad, por ejemplo C

delphi.com.ar
03-07-2006, 23:50:53
Vale aclarar que GetVolumeInformation retorna el número de serie lógico del disco y no físico, que puede ser duplicado, por ejemplo creándo imágenes de disco, por lo que no lo recomiendo utilzar como método de seguridad.