设为首页 加入收藏

TOP

delphi中WMI的使用(网卡是否接入)(一)
2019-08-23 00:31:47 】 浏览:163
Tags:delphi WMI 使用 网卡 是否 接入

WMI(Windows Management Instrumentation,Windows 管理规范)是一项核心的 Windows 管理技术;用户可以使用 WMI 管理本地和远程计算机。

通过使用WMI,我们可以很方便的获取到电脑的系统信息,但是很遗憾的是,我在网上找到的基本上都是对于某个功能的实现,比如查询IP,获取计算机名称,检测操作系统信息等等,如果只是在工作中用到了来查一下是没有问题的,但是,要想全面的了解WMI中的类库,来系统的掌握就很困难,WMI中有哪些系统的类,里面有哪些属性,这些属性都代表什么意思?MSND上面对于vbscript脚本实现的教程很详细,但是具体在delphi中对应的类型和参数名称是不一样的。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls ,ActiveX,comobj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}


 //网卡是否接入
function GetNetworkConnected(const sName: string): boolean;
var
  C: Cardinal;
  Enum: IEnumVariant;
  Wmi, Objs, Obj, V: OleVariant;
begin
  Result := False;
  Wmi := CreateOleObject('WbemScripting.SWbemLocator');
  try
    // ConnectServer无参表示连接本机      NetConnectionStatus=2 表示已经接入 7表示断开
    Objs := Wmi.ConnectServer().ExecQuery('Select * from Win32_NetworkAdapter WHERE NetConnectionStatus=2');
    Enum := IEnumVariant(IUnknown(Objs._NewEnum));
    Enum.Reset;
    //迭代信息
    while Enum.Next(1, Obj, C) = S_OK do
    begin
      V := Obj.Properties_.Item('Name', 0).Value;
      if VarIsClear(V) or VarIsNull(V) then
        Continue;
      if V=sName then
      begin
         Result:=True;
         Break
      end;
    end;
  finally
    Wmi := Unassigned;
  end;
end;




procedure TForm1.Button1Click(Sender: TObject);

begin
  ShowMessage(booltostr(GetNetworkConnected(Edit1.Text)));
end;

end.

 

因为WMI中通用的类大多是Win32_开头的,这里只需要传递后面的部分。

那么下一步,怎么知道我需要的是什么参数呢?以获取计算机名为例:

str := GetWMIProperty('OperatingSystem','CSName');即可获得。

当然,计算机名信息是比较常用的,在好几个类里面都有。

Win32_开头的类有:

Win32_Account
Win32_ActiveRoute
Win32_AutochkSetting
Win32_BaseBoard
Win32_BaseService
Win32_BIOS
Win32_BootConfiguration
Win32_Bus
Win32_ComputerSystem
Win32_ComputerSystemWindowsProductActivation
Win32_Desktop
Win32_DesktopMonitor
Win32_DeviceSettings
Win32_DiskDrive
Win32_DiskDrivePhysicalMedia
Win32_DisplayConfiguration
Win32_Environment
Win32_FontIntoAction
Win32_Group
Win32_IDEController
Win32_IP4PersistedRouteTable
Win32_IP4RouteTable
Win32_Keyboard
Win32_LogicalDisk
Win32_LogicalProgramGroup
Win32_LogonSession
Win32_MappedLogicalDisk
Win32_MemoryDevice
Win32_MotherboardDevice
Win32_NetworkAdapter
Win32_NetworkAdapterConfiguration
Win32_NetworkAdapterSetting
Win32_NetworkClient
Win32_NetworkConnection
Win32_OperatingSystem
Win32_PerfFormattedData_RemoteAccess_RASPort
Win32_PerfFormattedData_RemoteAccess_RASTotal
Win32_PerfRawData_RemoteAccess_RASPort
Win32_PhysicalMedia
Win32_PhysicalMemory
Win32_PNPDevice
Win32_PortConnector
Win32_POTSModem
Win32_POTSModemToSerialPort
Win32_Printer
Win32_PrinterConfiguration
Win32_Process
Win32_Processor
Win32_Product
Win32_ProgramGroup
Win32_ScheduledJob
Win32_SerialPort
Win32_SerialPortConfiguration
Win32_SerialPortSetting
Win32_Service
Win32_ServiceControl
Win32_SoundDevice
Win32_StartupComma
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Delphi中常用字符串处理函数 下一篇C++结构体与Delphi结构体相互传参..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目