0

我检查了来自 microsoft technet 论坛的 VloumeID 工具和来自“ http://www.xboxharddrive.com/freeware.html ”的“硬盘序列号更改”工具。但这些工具只提供更改 VolumeID。有没有一种安全的方法来生成一个新的而不与同一台 PC 上可能存在的其他逻辑驱动器的其他 VolumeID 冲突

4

1 回答 1

4

我假设您想以编程方式设置卷序列号。

基于当前日期/时间生成卷序列号 (VSN)。确切的实现细节可能因操作系统版本和/或用于格式的工具而异。

有关更多信息,请参阅以下链接:

从 Rufus 源代码:

/*
* 28.2 CALCULATING THE VOLUME SERIAL NUMBER
*
* For example, say a disk was formatted on 26 Dec 95 at 9:55 PM and 41.94
* seconds. DOS takes the date and time just before it writes it to the
* disk.
*
* Low order word is calculated: Volume Serial Number is:
* Month & Day 12/26 0c1ah
* Sec & Hundrenths 41:94 295eh 3578:1d02
* -----
* 3578h
*
* High order word is calculated:
* Hours & Minutes 21:55 1537h
* Year 1995 07cbh
* -----
* 1d02h
*/

static DWORD GetVolumeID(void)
{
SYSTEMTIME s;
DWORD d;
WORD lo,hi,tmp;

GetLocalTime(&s);

lo = s.wDay + (s.wMonth << 8);
tmp = (s.wMilliseconds/10) + (s.wSecond << 8);
lo += tmp;

hi = s.wMinute + (s.wHour << 8);
hi += s.wYear;

d = lo + (hi << 16);
return d;
}

转换为以下 Delphi 代码:

type
  TVolumeId = record
    case byte of
      0: (Id: DWORD);
      1: (
        Lo: WORD;
        Hi: WORD;
      );
  end;

function GetVolumeID: DWORD;
var
  dtNow: TDateTime;
  vlid: TVolumeId;
  st: SYSTEMTIME;
begin
  GetLocalTime(st);
  vlid.Lo := st.wDay + (st.wMonth shl 8);
  vlid.Lo := vlid.Lo + (st.wMilliseconds div 10 + (st.wSecond shl 8));

  vlid.Hi := st.wMinute + (st.wHour shl 8);
  vlid.Hi := vlid.Hi + st.wYear;

  Result := vlid.Id
end;
于 2013-03-29T13:55:37.390 回答