如何获得电脑的品牌和型号?

slhcrj9b  于 2022-10-16  发布在  其他
关注(0)|答案(1)|浏览(183)

我找了很多,但我找不到解决方案,我找到了这个:

function GetLocalComputerName(
  NameType: TComputerNameFormat = ComputerNameDnsHostname): string;
var
  len: DWORD;
begin
  len:= 0;
  GetComputerNameEx(NameType, nil, len); //get length
  SetLength(Result, len - 1);
  if not GetComputerNameEx(NameType, PChar(Result), len) then RaiseLastOSError;
end;

但这将返回计算机的名称,我想要获取品牌,例如Samsung和型号。

kkih6yb8

kkih6yb81#

对于Windows操作系统,您可以使用WMI:

//This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.9.9.482, http://code.google.com/p/wmi-delphi-code-creator/

procedure  GetWin32_ComputerSystemProductInfo;
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 * FROM Win32_ComputerSystemProduct','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin 
    Writeln(Format('Vendor:    %s',[String(FWbemObject.Vendor)]));// String
    FWbemObject:=Unassigned;
  end;
end;

相关问题