Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Tool für selektives AutoPlay? [Windows 7]
15. Aug 2011, 15:29
WM_DEVICECHANGE
GetVolumeInformation
RegisterDeviceNotification + DEV_BROADCAST_VOLUME
Das sollte helfen
Habe hier mal auf die schnelle einen sehr hässlichen, aber funktionierenden Code zusammengeschustert:
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
private
{ Private-Deklarationen }
public
procedure WMDevChange( var Msg: TMessage); message WM_DEVICECHANGE;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
DBT_DEVICEARRIVAL = $8000;
DBT_DEVICEREMOVECOMPLETE = $8004;
{ TForm1 }
procedure TForm1.WMDevChange( var Msg: TMessage);
var DevName: Array[0..MAX_PATH] of Char;
FileSys: Array[0..MAX_PATH] of Char;
SN: DWORD;
DevFlags, MaxLen: DWORD;
begin
if Msg.WParam = DBT_DEVICEARRIVAL then
begin
GetVolumeInformation(' G:\',@DevName[0],MAX_PATH+1,@SN,MaxLen,DevFlags,@FileSys[0],MAX_PATH+1);
ListBox1.Items.Add(' Laufwerk: G:');
ListBox1.Items.Add(' Bezeichnung: ' + String(DevName));
ListBox1.Items.Add(' Dateisystem: ' + String(FileSys));
ListBox1.Items.Add(' Serien-Nr.: ' + IntToStr(SN));
end
else
if Msg.WParam = DBT_DEVICEREMOVECOMPLETE then
ListBox1.Items.Clear;
end;
end.
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
Geändert von Neutral General (15. Aug 2011 um 15:46 Uhr)
|
|
Zitat
|