Recent

Author Topic: رقم تسلسلي للقرص الصلب  (Read 3304 times)

Al-Eid

  • Jr. Member
  • **
  • Posts: 75
رقم تسلسلي للقرص الصلب
« on: August 17, 2023, 02:07:52 pm »
السلام عليكم
بحثت عن كيفية إيجاد الرقم التسلسلي للقرص الصلب فوجدة في هذا المنتدى موضوع تحدث عن هذه الوحدة
hddinfo ولكن لم أعرف طريقة إستعمالها
ممكن شرح طريقة إستعمالها مع العلم أنها في المرفق


KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: رقم تسلسلي للقرص الصلب
« Reply #1 on: August 17, 2023, 04:37:32 pm »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows, SysUtils;
  7.  
  8. function GetVolumeID(DriveChar: Char): string;
  9. var
  10.   MaxFileNameLength, VolFlags, SerNum: DWord;
  11. begin
  12.   if GetVolumeInformation(PAnsiChar(DriveChar + ':\'), nil, 0, @SerNum, MaxFileNameLength, VolFlags, nil, 0) then
  13.   begin
  14.     Result := IntToHex(SerNum, 8);
  15.     Insert('-', Result, 5);
  16.   end
  17.   else
  18.     Result := '';
  19. end;
  20.  
  21. procedure GetHardDriveSerialNumbers;
  22. var
  23.   C: Char;
  24.   S: string;
  25. begin
  26.   for C := 'C' to 'Z' do
  27.   begin
  28.     S := GetVolumeID(C);
  29.     if S <> '' then
  30.       WriteLn('Drive ', C, ': ', S);
  31.   end;
  32. end;
  33.  
  34. begin
  35.   GetHardDriveSerialNumbers;
  36.   ReadLn;
  37. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Al-Eid

  • Jr. Member
  • **
  • Posts: 75
Re: رقم تسلسلي للقرص الصلب
« Reply #2 on: August 19, 2023, 09:10:51 am »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows, SysUtils;
  7.  
  8. function GetVolumeID(DriveChar: Char): string;
  9. var
  10.   MaxFileNameLength, VolFlags, SerNum: DWord;
  11. begin
  12.   if GetVolumeInformation(PAnsiChar(DriveChar + ':\'), nil, 0, @SerNum, MaxFileNameLength, VolFlags, nil, 0) then
  13.   begin
  14.     Result := IntToHex(SerNum, 8);
  15.     Insert('-', Result, 5);
  16.   end
  17.   else
  18.     Result := '';
  19. end;
  20.  
  21. procedure GetHardDriveSerialNumbers;
  22. var
  23.   C: Char;
  24.   S: string;
  25. begin
  26.   for C := 'C' to 'Z' do
  27.   begin
  28.     S := GetVolumeID(C);
  29.     if S <> '' then
  30.       WriteLn('Drive ', C, ': ', S);
  31.   end;
  32. end;
  33.  
  34. begin
  35.   GetHardDriveSerialNumbers;
  36.   ReadLn;
  37. end.

لقد لاحظت إنه يعمل مع تقسيمات القرص ولكن أبحث عن رقم التسلسلي للقرص كاملا إذا أمكن

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: رقم تسلسلي للقرص الصلب
« Reply #3 on: August 23, 2023, 08:45:54 am »
Demo attached
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Al-Eid

  • Jr. Member
  • **
  • Posts: 75
Re: رقم تسلسلي للقرص الصلب
« Reply #4 on: August 24, 2023, 03:58:14 pm »
Demo attached

يتوقف عند رقم 2 أنظر للصورة في المرفقات

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: رقم تسلسلي للقرص الصلب
« Reply #5 on: August 24, 2023, 04:46:17 pm »
You need to execute it on the commandline, it is how the original class was designed.

Attached updated version that not raise exceptions.
Added 2 new fields to properly play with this class and easy iterate over, depends what you want choose AvailableDrives or AvailableLetters, or both as in demo.
Code: Pascal  [Select][+][-]
  1. var
  2.   HDD: THDDInfo;
  3.   i: Integer;
  4. begin
  5.   HDD := THDDInfo.Create;
  6.   try
  7.     // display logical drive information
  8.     for i := Low(HDD.AvailableDrives) to High(HDD.AvailableDrives) do
  9.       HDDInfos(HDD, HDD.AvailableDrives[i]);
  10.     // display partition serial number
  11.     for i := Low(HDD.AvailableLetters) to High(HDD.AvailableLetters) do
  12.       begin
  13.         HDD.DriveLetter := HDD.AvailableLetters[i];
  14.         if HDD.IsInfoAvailable then
  15.           WriteLn('Serial for Letter ', HDD.AvailableLetters[i], ': ', HDD.SerialLetter)
  16.         else
  17.           WriteLn('Drive ', HDD.AvailableLetters[i], ' has no Serial number');
  18.       end;
  19.   finally
  20.     HDD.Free;
  21.   end;
  22.   ReadLn;
  23. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Al-Eid

  • Jr. Member
  • **
  • Posts: 75
Re: رقم تسلسلي للقرص الصلب
« Reply #6 on: August 26, 2023, 03:48:50 pm »
You need to execute it on the commandline, it is how the original class was designed.

Attached updated version that not raise exceptions.
Added 2 new fields to properly play with this class and easy iterate over, depends what you want choose AvailableDrives or AvailableLetters, or both as in demo.
Code: Pascal  [Select][+][-]
  1. var
  2.   HDD: THDDInfo;
  3.   i: Integer;
  4. begin
  5.   HDD := THDDInfo.Create;
  6.   try
  7.     // display logical drive information
  8.     for i := Low(HDD.AvailableDrives) to High(HDD.AvailableDrives) do
  9.       HDDInfos(HDD, HDD.AvailableDrives[i]);
  10.     // display partition serial number
  11.     for i := Low(HDD.AvailableLetters) to High(HDD.AvailableLetters) do
  12.       begin
  13.         HDD.DriveLetter := HDD.AvailableLetters[i];
  14.         if HDD.IsInfoAvailable then
  15.           WriteLn('Serial for Letter ', HDD.AvailableLetters[i], ': ', HDD.SerialLetter)
  16.         else
  17.           WriteLn('Drive ', HDD.AvailableLetters[i], ' has no Serial number');
  18.       end;
  19.   finally
  20.     HDD.Free;
  21.   end;
  22.   ReadLn;
  23. end.

ممتاز
شكرا وألف شكرا
Thanks and a thousand thanks
Thank you very much



 

TinyPortal © 2005-2018