-
-
Save CynicRus/641d7687ca1f46f9cbcfd036e1bb4f31 to your computer and use it in GitHub Desktop.
get windows key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
CharMap: array [0..23] of char = 'BCDFGHJKMPQRTVWXY2346789'; | |
var | |
ProductID: array of byte; | |
IdPart: array [0..14] of byte; | |
Registry: TRegistry; | |
DataSize: integer; | |
Key: ansistring; | |
i, j, c: integer; | |
begin | |
Registry := TRegistry.Create; | |
try | |
Registry.RootKey := HKEY_LOCAL_MACHINE; | |
if Registry.OpenKeyReadOnly('SOFTWARE\Microsoft\Windows NT\CurrentVersion') then | |
begin | |
key := ''; | |
DataSize := 0; | |
DataSize := Registry.GetDataSize('DigitalProductId'); | |
if DataSize > 0 then | |
begin | |
SetLength(productID, DataSize); | |
FillChar(IdPart, 15, 0); | |
Registry.ReadBinaryData('DigitalProductId', Pointer(productID)^, | |
Length(productID)); | |
Move(Pointer(productID[52])^, Pointer(idPart[0])^, Length(IdPart)); | |
i := 0; | |
j := 0; | |
while i < 25 do | |
begin | |
c := 0; | |
j := Length(IdPart) - 1; | |
while j >= 0 do | |
begin | |
c := (c shl 8) xor idpart[j]; | |
idpart[j] := byte(c div 24); | |
c := c mod 24; | |
Dec(j); | |
end; | |
if (i > 0) and (i mod 5 = 0) then | |
key := key + '-'; | |
key := key + charmap[c]; | |
Inc(i); | |
end; | |
end; | |
end; | |
Memo1.Lines.Clear; | |
memo1.Lines.Add(key); | |
finally | |
productID := nil; | |
Registry.Free; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment