简体   繁体   中英

generate a new Volume ID

i checked the VloumeID tool from microsoft technet forum and the "Hard Disk Serial Number Change" tool from " http://www.xboxharddrive.com/freeware.html ". But these tools only offer to change the VolumeID. is ther a safe way to generate a new one without conflicting with other VolumeIDs of other logical drive that may exist on the same PC

I am assuming that you want to set the volume serial number programmatically.

A Volume Serial Number (VSN) is generated based on the current date/time. Exact implementation details may differ per OS version and/or the tool used for the format.

See the following links for more info:

From the Rufus source code:

/*
* 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;
}

Which translates to the following Delphi Code:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM