如何获取计算机的品牌及型号信息?
获取Windows电脑品牌与型号(Delphi实现)
要获取如Samsung这类的品牌及型号信息,需要通过**WMI(Windows Management Instrumentation)**读取系统硬件信息,以下是具体的Delphi实现方案:
核心实现代码
uses SysUtils, ComObj, ActiveX; type TComputerHardwareInfo = record Manufacturer: string; // 品牌厂商 Model: string; // 设备型号 end; function GetComputerHardwareInfo: TComputerHardwareInfo; var WMIService: OleVariant; Items: OleVariant; Item: OleVariant; Enum: IEnumVariant; FetchResult: LongWord; begin // 初始化COM环境 CoInitialize(nil); try // 连接本地WMI服务 WMIService := GetOleObject('winmgmts:\\.\root\CIMV2'); // 查询Win32_ComputerSystem类,提取品牌和型号字段 Items := WMIService.ExecQuery('SELECT Manufacturer, Model FROM Win32_ComputerSystem'); Enum := IUnknown(Items._NewEnum) as IEnumVariant; if Enum.Next(1, Item, FetchResult) = S_OK then begin Result.Manufacturer := Trim(Item.Manufacturer); Result.Model := Trim(Item.Model); end else begin Result.Manufacturer := '未知品牌'; Result.Model := '未知型号'; end; except on E: Exception do begin Result.Manufacturer := '获取失败: ' + E.Message; Result.Model := ''; end; end; CoUninitialize; end; // 使用示例 procedure TForm1.Button1Click(Sender: TObject); var HardwareInfo: TComputerHardwareInfo; begin HardwareInfo := GetComputerHardwareInfo; ShowMessage('品牌: ' + HardwareInfo.Manufacturer + #13#10 + '型号: ' + HardwareInfo.Model); end;
关键说明
- 该方案依赖Windows系统内置的WMI服务,Windows XP及以上版本均原生支持,无需额外安装组件。
- 普通用户权限即可正常获取信息,若出现获取失败,可尝试以管理员身份运行程序,或检查COM组件注册状态。
Win32_ComputerSystem类返回的信息直接来自系统硬件注册表项,数据准确性较高。
内容的提问来源于stack exchange,提问作者Pro Boy
相关产品推荐
相关产品推荐

