Hey! We actually use the following code to get the system serial - maybe that can help:
function GetSystemSerial : string;
var FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin
CoInitialize(nil);
try
result:='';
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
// ATT: we had a case, where on a Win2016 server, the system service failed to
// execute this command. Changing the service to a local user solved the problem.
// There has been 2 cases where the WMI service was corrupted or was not running.
// -> to check: enter WmiMgmt.msc in the console and right click on the local wmi - control -> Properties
// if an error occurs the repository seems to be corrupt
// one time it helped to reset and rebuild the repository:
// https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-rebuilding-the-wmi-repository/ba-p/373846
try
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
except
on e : Exception do
begin
OutputDebugString(PChar('WMI service not properly running: '+e.Message+#13#10+
'https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-rebuilding-the-wmi-repository/ba-p/373846'));
raise;
end;
end;
// todo: if we still support winxp this wmi class is not supported?!?
FWbemObjectSet:= FWMIService.ExecQuery('SELECT UUID FROM Win32_ComputerSystemProduct','WQL',$00000020 {wbemFlagForwardOnly});
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
if oEnum.Next(1, FWbemObject, iValue) = 0 then
result:=String(FWbemObject.UUID);
finally
CoUninitialize;
end;
end;
There is also another place where you could get some unique id:
// from http://www.nextofwindows.com/the-best-way-to-uniquely-identify-a-windows-machine
with OpenHKLMReadOnly('SOFTWARE\Microsoft\Cryptography', True) do
begin
AktMachineGuid:=ReadString('', 'MachineGuid', '');
Log('Machine guid: ' + AktMachineGuid);
Free;
end;
hope that helps!
kind regards
Mike