微软产品安装序列号
function DecodeMicrosoftDigitalProductID(const DigitalProductID: PChar; Len : Integer): string;
{
解码微软产品数字ID为可显示字符串,DigitalProcuctID存储在注册表中
微软许多产品都使用同样的方式来存储,例如Windows的安装序列号,Office的安装序列号等
}
const
charset = 'BCDFGHJKMPQRTVWXY2346789';
var
c: array[0..14] of Byte;
i ,j : Integer;
a: Cardinal;
begin
/// 产品数据为第$34字节开始的连续15个字节
if Len > $34 + 15 then
begin
/// 复制第34字节后的15字节数据到缓冲区
Move(DigitalProductID[$34], c, SizeOf(c));
for i:= 25 downto 1 do
begin
a := 0;
for j := 14 downto 0 do
begin
a := a shl $08;
Inc(a, c[j]);
c[j] := (a div $18) and $FF;
a := a mod $18;
end;
if (i mod 5 = 0) and (Result <> '') then Result := '-' + Result;
Result := charset[a + 1] + Result;
end;
end
else Result := 'N/A';
end;
function GetWindowsProductID: string;
{
返回Windows的安装序列号
}
const
RegistryKey = 'Software\Microsoft\Windows NT\CurrentVersion';
RegistryVal = 'DigitalProductId';
var
L: Integer;
b: PChar;
begin
/// 产品数据为第$34字节开始的连续15个字节
b := GetMemory(1);
if RegReadBinary(HKEY_LOCAL_MACHINE, RegistryKey, RegistryVal, b, L) then
Result := DecodeMicrosoftDigitalProductID(b, L);
end;
function GetOfficeXPProductID: string;
{
返回Office XP的安装序列号
}
const
RegistryKey = 'SOFTWARE\MICROSOFT\Office\10.0\Registration';
RegistryVal = 'DigitalProductId';
var
L: Integer;
b: PChar;
begin
/// 产品数据为第$34字节开始的连续15个字节
b := GetMemory(1);
if RegReadBinary(HKEY_LOCAL_MACHINE, RegistryKey, RegistryVal, b, L) then
Result := DecodeMicrosoftDigitalProductID(b, L);
end;