Autor Beitrag
Peter18
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Fr 25.05.12 16:51 
Ein freundliches Hallo an alle,

und wieder ein Datenträgerproblem: Ich möchte die Seriennummer eines wechselbaren Datenträgers ermitteln, um ihn eindeutig zu identifizieren. Dazu habe ich die "GetVolumeInformation" verwendet. Ich erhalte aber nur "1" als Ergebnis oder eine Fehlermeldung, wenn ich einen Pointer verwende.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function VolumeSN(Drive: string): string;
var
  OldErrorMode      : Integer;
  NotUsed, VolFlags : DWORD;
  SN                : LPDWORD;
  Buf               : array [0..MAX_PATH] of Char;
begin
  OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    GetVolumeInformation(PChar(Drive), Buf,
                         sizeof(Buf), SN, NotUsed, VolFlags,
                         nil0);
    Result := IntToStr( Integer( SN ) );
  finally
    SetErrorMode(OldErrorMode);
  end;
end;

Hat jemand einen Tipp?

Dank im voraus mit Grüßen von der Nordsee

Peter
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Fr 25.05.12 17:17 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function VolumeSN(Drive: Char): string;
var
 sn,cl,sf:DWord;
begin
  sn :=0;
  cl := 0;
  sf := 0;
  GetVolumeInformation(PChar(Drive + ':\') , nil0 , @SN  , cl  ,sf  , nil0);
  Result := IntToHex(HiWord(sn), 4) + '-' + IntToHex(Word(sn), 4);
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 25.05.12 17:44 
Wobei es wenig Sinn macht den Rückgabewert zu ignorieren... Wenn die Funktion fehlschlägt, sollte man das schon behandeln. ;-)
Peter18 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 26.05.12 11:33 
Hallo bummi, hallo jaenicke,

dank euch beiden, :D die Hilfe hat das nicht hergegeben, aber warscheinlich hätte ich mich auch noch bei Windows umsehen sollen.

Danke noch mal und Grüße von der Nordsee

Peter