@LexLi is correct that there are already questions about reading wmic
output into Inno Setup, for example: Parsing output of wmic in Inno Setup
But my answer there also says, that it is not easy, as wmic
outputs UTF-16 and that it is better to use WMI API. See Is there a way to read the system's information in Inno Setup.
function InitializeSetup(): Boolean;
var
WbemLocator, WbemServices, Bios: Variant;
Query: string;
begin
Result := True;
WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('.', 'root\CIMV2');
Query := 'SELECT SerialNumber FROM Win32_BIOS';
Bios := WbemQuery(WbemServices, Query);
if not VarIsNull(Bios) then
begin
Code := GetSHA1OfString(Trim(Bios.SerialNumber) + 'Salt');
Log(Format('Code is [%s]', [Code]));
end
else
begin
MsgBox('Cannot get computer code', mbError, MB_OK);
Result := False;
end;
end;
The above code stores the hashed serial number into Code
variable. You can then use it anywhere you like.