Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Número Id de un disco o disquete (https://www.clubdelphi.com/foros/showthread.php?t=80583)

dec 02-07-2006 00:36:05

Número Id de un disco o disquete
 
¿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
    { 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.

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

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.


La franja horaria es GMT +2. Ahora son las 05:38:13.

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