其他分享
首页 > 其他分享> > Delphi WMI[3] 获取硬盘ID的方法(无需管理员权限)

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  更新时间:

标签:Tmp,Enum,end,Delphi,OleVariant,Locator,WMI,ID
来源: https://www.cnblogs.com/guorongtao/p/15092960.html