¿Cómo puedo obtener el nº de id de un disco o diskette?
(Obtenido de Borland)
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
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');
Directory := MyReg.ReadString('Shell Folders','Desktop','');
WFileName := Directory+'\FooBar.lnk';
MyPFile.Save(PWChar(WFileName),False);
MyReg.Free;
end;
end.
Código Delphi
[-]
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