簡體   English   中英

從Win32從C或Delphi獲取BIOS UUID

[英]Get BIOS UUID from C or Delphi from Win32

VMWare配置文件包含一行

uuid.bios = "56 4d ed cf 3c cd 63 20-53 78 95 86 26 92 22 c8"

而afaik大多數(每個?)物理BIOS都有這樣一個UUID。 是否有任何Windows API調用來獲取此標識符?

我已經嘗試了WMI類Win32_ComputerSystemProduct.UUID屬性,但該值與uuid.bios值不同。 HKEY_LOCAL_MACHINE \\ Software \\ Microsoft \\ Cryptography \\ MachineGuid的值也不同。

該值稱為Universal Unique ID number並且是SMBIOS表的一部分,如果您使用Win32_BIOS WMI類的SerialNumber屬性,您將獲得uuid.bios (來自vmx文件)條目加上前綴VMware-的相同ID。 (例如: VMware-56 4d af ac d8 bd 4d 2c-06 df ca af 89 71 44 93

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

// The Win32_BIOS class represents the attributes of the computer system's basic input/output services (BIOS) that are installed on the computer.

procedure  GetWin32_BIOSInfo;
const
  WbemUser            ='';
  WbemPassword        ='';
  WbemComputer        ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT SerialNumber FROM Win32_BIOS','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  if oEnum.Next(1, FWbemObject, iValue) = 0 then
    Writeln(Format('SerialNumber    %s',[String(FWbemObject.SerialNumber)]));// String
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_BIOSInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); 
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;      
end.

如果要返回不帶VMware-前綴的相同uuid,則必須直接讀取SMBIOS表 (檢查系統信息表類型1和UUID字段),嘗試本文Reading the SMBios Tables using Delphi包含一個示例代碼列表這個價值。

UUID格式

System Management BIOS (SMBIOS) Reference Specification

UUID是一種設計為在時間和空間上都是唯一的標識符。 它不需要中央注冊過程。 UUID長128位。 其格式在RFC 4122中描述,但實際的字段內容是不透明的,對SMBIOS規范並不重要,SMBIOS規范僅涉及字節順序。 表10顯示了字段名稱; 這些字段名稱,特別是多路復用字段,遵循歷史慣例。

在此輸入圖像描述

盡管RFC 4122建議所有字段的網絡字節順序,但PC行業(包括ACPI,UEFI和Microsoft規范)始終對前三個字段使用little-endian字節編碼:time_low,time_mid,time_hi_and_version。 同樣的編碼(也稱為有線格式)也應該用於UUID的SMBIOS表示。

因此,UUID {00112233-4455-6677-8899-AABBCCDDEEFF}將表示為:33 22 11 00 55 44 77 66 88 99 AA BB CC DD EE FF。

如果該值全部為FFh,則系統中當前不存在該ID,但可以設置該ID。 如果該值全部為00h,則系統中不存在該ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM