创建 WMI 应用程序或脚本Creating a WMI Application or Script

适用于 ActiveX 对象的任何脚本语言(如 VBScript)都可访问 WMI 数据。Any scripting language, such as VBScript, that works with ActiveX objects can access WMI data. 应用程序可以使用 适用于 wmi 的 COM API 或 Visual Basic 中使用 wbemdisp.tlb 类型库wmi 的脚本编写 API访问 c + + 中的 wmi。Applications can access WMI in C++, using the COM API for WMI or in Visual Basic, using the Wbemdisp.tlb type library and the Scripting API for WMI. .. 可以通过编写脚本、Active Server 页面 (ASP) 或 HTML 应用程序 (HTA) 来获取数据。You can obtain data through WMI by writing a script, an Active Server Page (ASP), or an HTML application (HTA). 你还可以使用 Windows PowerShell 来获取数据或编写脚本。You can also use Windows PowerShell to obtain data or write scripts. 有关详细信息,请参阅通过 Windows PowerShell在 WMI 中编写脚本和入门。For more information, see Scripting in WMI and Getting Started with Windows PowerShell. TechNet ScriptCenter https://www.microsoft.com/technet 包含数以百计的脚本编写示例。The TechNet ScriptCenter at https://www.microsoft.com/technet contains hundreds of scripting examples. 有关打印和联机资源的详细信息,请参阅 详细信息For more information about print and online resources, see Further Information.

以下过程描述了如何连接到 WMI 服务和数据存储。The following procedure describes how to connect to the WMI service and data store.

连接到 WMI 服务和数据存储To connect to the WMI service and data store

  1. 在特定计算机上找到 WMI 服务。Locate the WMI service on a specific machine.
  2. 连接到一个或多个 WMI 命名空间。Connect to one or more WMI namespaces.

这些操作在 c + +、Visual Basic、.NET Framework 语言或使用脚本时有所不同。These operations are different in C++, Visual Basic, .NET Framework languages, or when using a script. 脚本和 Visual Basic 应用程序必须访问其实例由现有提供程序提供的数据的类。Scripts and Visual Basic applications must access classes whose instances are supplied with data by existing providers. 但用 c + + 编写的应用程序可以执行更多操作。But applications written in C++ can do more. 例如,用 c + + 编写的应用程序可以发送事件,但 WMI 脚本只能订阅接收事件。For example, an application written in C++ can send events, but a WMI script can only subscribe to receive events.

WMI 提供程序只能使用 c + + 或 .NET Framework 来编写。A WMI provider can be written only in C++ or using the .NET Framework. 有关以 c # 或 Visual Basic .NET 编写应用程序的详细信息,请参阅 WMI .Net 概述For more information about writing applications in C# or Visual Basic .NET, see WMI .NET Overview.

有关为 WMI 创建应用程序和脚本的详细信息,请参阅:For more information about creating applications and scripts for WMI, see:

若要执行大多数任务,请使用预安装的 WMI 类To perform most tasks, use the preinstalled WMI classes.

使用 WMIUsing WMI