1
2 //This example get the give hard drive serial number and Volume label
3
4 #include <vcl.h>
5 #pragma hdrstop
6
7 #include "Unit1.h"
8 #include "dir.h"
9 #include "stdio.h"
10
11
12 //---------------------------------------------------------------------------
13 #pragma package(smart_init)
14 #pragma resource "*.dfm"
15 TForm1 *Form1;
16 //---------------------------------------------------------------------------
17 __fastcall TForm1::TForm1(TComponent* Owner)
18 : TForm(Owner)
19 {
20 }
21 AnsiString TForm1::GetHardDiskSerial(String DriveChar){
22
23 String RootPathName = DriveChar +":\\";
24 char VolumeNameBuffer[_MAX_PATH], FileSystemBuffer[_MAX_PATH];
25 DWORD VolumeSerialNumber, MaximumComponentLength, FileSystemFlags;
26 AnsiString SerialNumber;
27
28 GetVolumeInformation(
29 RootPathName.c_str(),
30 VolumeNameBuffer,
31 sizeof(VolumeNameBuffer),
32 &VolumeSerialNumber,
33 &MaximumComponentLength,
34 &FileSystemFlags,
35 FileSystemBuffer,
36 sizeof(FileSystemBuffer) );
37
38 int lo, hi;
39 char lob[8], hib[8];
40
41 lo = VolumeSerialNumber & 0xFFFF;
42 hi = (VolumeSerialNumber >> 16) & 0xFFFF;
43
44 sprintf(lob, "%04x", lo);
45 sprintf(hib, "%04x", hi);
46
47 SerialNumber = UpperCase(AnsiString(hib)) + "-" +
48 UpperCase(AnsiString(lob));
49
50 SerialNumber="Label="+ (AnsiString)VolumeNameBuffer+" Serial=
51 "(AnsiString)SerialNumber;
52
53
54 return SerialNumber;
55
56
57 }
58
59 //---------------------------------------------------------------------------
60
61
62 void __fastcall TForm1::Button1Click(TObject *Sender)
63 {
64 ShowMessage(GetHardDiskSerial('c'));
65 }
66 //---------------------------------------------------------------------------
67
|