Delphi WMI[3] 获取硬盘ID的方法(无需管理员权限)

Delphi WMI[3] 获取硬盘ID的方法(无需管理员权限)

function GetWMIHardNo() : String;
var
  Locator : OleVariant;
  WMI     : OleVariant;
  RET     : OleVariant;
  Enum    : IEnumVariant;
  Tmp     : OleVariant;
  Value   : Cardinal;
begin
  Result := '';

  try
    Locator := CreateOleObject('WbemScripting.SWbemLocator');
    WMI     := Locator.ConnectServer('.', '', '', '');
    RET     := WMI.ExecQuery('Select * From  Win32_DiskDrive');  //Win32_DiskDrive  Win32_PhysicalMedia
    Enum    := IUnknown(RET._NewEnum) as IEnumVariant;

    while (Enum.Next(1, Tmp, Value)= S_OK) do
    begin
      Result := Trim(Tmp.SerialNumber);

      if (Length(Result) > 0) then
      begin  break; end;
    end;
    
  finally
    Locator := UnAssigned;
  end;
  
end;

  

 

 

 

 

创建时间:2021.08.03  更新时间:

上一篇:整个目录的拷贝 - Delphi - TDirectory


下一篇:leetcode:208. 实现 Trie (前缀树)