Jump to content

How does UNIGUI get the device information


风吹小机机

Recommended Posts

The main purpose of obtaining equipment information is to verify the validity of the software

What good way do you have? No,

Under the application program, this code can obtain the device information

But an error is reported in UNGUI

uses
  NB30,
  Winapi.ActiveX, System.Win.ComObj;

{$region 'function GetWMIProperty(WMIType, WMIProperty: AnsiString): string;'}
function GetWMIProperty(WMIType, WMIProperty: AnsiString): string;
var
  Wmi, Objs, Obj: OleVariant;
  Enum: IEnumVariant;
  😄 Cardinal;
begin
  try
    Wmi := CreateOleObject(AnsiString('WbemScripting.SWbemLocator'));
    Objs := Wmi.ConnectServer(AnsiString('.'), AnsiString('root\cimv2')).ExecQuery(AnsiString('Select * from Win32_' + WMIType));
    Enum := IEnumVariant(IUnknown(Objs._NewEnum));
    Enum.Reset;
    Enum.Next(1, Obj, C);
    Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
    if VarIsArray(Obj) then
      Result := Obj[0]
    else
      Result := Obj;
  except
    Result := 'error';
  end;
end;
{$ENDREGION}
//获取计算机名称
function GetComputerName: string;
begin
  Exit(GetWMIProperty('OperatingSystem', 'CSName'));
end;
//获取BISO序列号
function GetBIOSSerialNumber: string;
begin
  Exit(GetWMIProperty('BIOS', 'SerialNumber'));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add(GetComputerName);
  Memo1.Lines.Add(GetBIOSSerialNumber);
end;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...