Windows Management Instrumentation

Un livre de Wikilivres.
Aller à : navigation, rechercher
Cette page est une feuille volante

Il faudrait la ranger dans un wikilivre où elle aurait sa place.

Windows Management Instrumentation (WMI) est l’implémentation de Microsoft du Web-Based Enterprise Management (WBEM), le standard du Distributed Management Task Force (DMTF). Il prend en charge le modèle de données CIM (Common Information Model), qui décrit les objets d'un environnement de gestion.

WMIC (Windows Management Instrumentation Command-line) fournit une interface de ligne de commande dans l'Infrastructure de gestion Windows (WMI) qui permet de tirer parti de WMI pour gérer les ordinateurs. Windows PowerShell permet aussi d'utiliser simplement WMI depuis la ligne de commande.

Qu'est-ce que WMI ?[modifier | modifier le wikicode]

Translation arrow.svg
Demande de traduction

Cette page nécessite une traduction.
Si vous connaissez cette langue et le sujet de la page, vous pouvez poursuivre ou corriger la traduction.

WMI is the Microsoft implementation of the Common Information Model (CIM) initiative developed by the Distributed Management Task Force (DMTF). The DMTF is an association of various computer and software companies (e.g. Novell, Microsoft, Cisco, HP, etc.) developing standards in the Enterprise management space. (See for more information.) As large Enterprises have many computers with many software environments, managing these diverse environments can be a real challenge. In order to unify the management techniques for the sake of simplicity, the DMTF defined CIM to represent real-world manageable entities in a unified way. The CIM object model is an object data model using terms and semantic that is unique to all constructors and software developers. This object model is implemented in a database called the CIM repository, as visible in the figure below.

Based on the CIM model, WMI includes real-world manageable components, available from the DMTF standards with some specific extensions that represent the various Windows components. Moreover, WMI exposes a collection of COM scriptable objects that allow various applications to take advantage of the management information. WMI is the Microsoft implementation of CIM.

As part of the installation process, most of the Microsoft applications available today (e.g. SQL 2000, Exchange 2000/2003, Office 2000/XP/2003, Internet Explorer 6.0, Host Integration Server, Automated Deployment Services) extend the standard CIM object model to add the representation of their manageable entities in the CIM repository. This representation is called a class, and it exposes information through properties and allows the execution of some actions via methods. The access to the manageable entities is made via a software component, called a “provider” which is nothing else than a DLL implementing a COM object written in C/C++ (See note at the end of this section). Because a provider is designed to access some specific management information, the CIM repository is also logically divided into several areas called a namespace. Each namespace contains a set of providers with their related classes specific to a management area (i.e. RootDirectorydap for active directory, rootsnmp for snmp information or rootmicrosoftiisv2 for internet information server information).

to locate the huge amount of management information available from the cim repository, wmi comes with a sql-like language called the wmi query language (wql). briefly, wql is a subset of the standard american national standards institute structured query language (ansi sql) with minor semantic changes. a basic wql query remains fairly understandable for people with a basic sql knowledge. therefore, wql is dedicated to wmi and is designed to perform queries against the cim repository to retrieve information or get event notifications.

more information about some of the terms that cim is using is available on msdn at and

What is the overall development process?[modifier | modifier le wikicode]

Because WMI abstracts the manageable entities with CIM and a collection of providers, the development of a provider implies several steps. Although there are 4 major steps with some sub-steps, each of them taken separately are quite easy to execute. These can be summarized as follows:

Step 1 – Create the manageable entity model

  • Define a model
  • Implement the model

Step 2 – Create the WMI Provider

  • Determines the provider type to implement
  • Determines the hosting model of the provider
  • Create the provider template with the ATL wizard
  • Implement the code logic in the provider
  • Register the provider with WMI and the system

Step 3 - Test the provider

Step 4 - Create consumer sample codes

Why is it important to write a WMI provider for our customers?[modifier | modifier le wikicode]

Since the release of the first WMI implementation during the Windows NT 4.0 SP4 era (as an out-of-band download), Microsoft never stopped to add WMI providers in Windows. Under Windows NT 4.0, Microsoft had roughly 15 WMI providers available once WMI was installed. When Windows 2000 was released, customers discovered 29 WMI providers part of the Operating System installation. More recently, with the release of Windows Server 2003, Microsoft included in the platform more than 80 WMI providers. This has been a sign for many customers that WMI became at Microsoft the “ubiquitous” management layer of Windows, even if this commitment has never been explicit from Microsoft. This is the net result of the on-going work made during the last Windows release.

During these last years, due to a constant increasing exposure of management data through WMI in Windows, more and more people in the field started to develop scripts and automation procedures based on WMI. Beyond the scripting needs, most leading management software in the world, such as MOM, SMS, ADS, HP OpenView for Windows (HPOV), BMC, CA, or Kaseya are WMI-enabled and capable to consume and provide WMI information through various User Interfaces. This enables administrators and operators, not capable to script or program on top of WMI, to enjoy the benefits of WMI without even learning about WMI. However, if they want to, because WMI is scriptable, it gives the opportunity to any of them to consume WMI information from scripts or from any Enterprise Management software that is WMI-aware.

These trends have made WMI very popular among our customers management communities. Tons of references and publications exist on the Internet about WMI. At the same time, this story increased our customer expectations because the management communities leveraging WMI today expect our management layer to be predictable and consistent through WMI for more and more Windows manageable components. This also means that our customers expect to leverage the knowledge and investment made in WMI during these past years to improve, pursue and achieve their business goals at lower cost.

What WMI offers for free out-of-the box?[modifier | modifier le wikicode]

For someone willing to develop one or many WMI providers, WMI offers many features out of the box. Here are the most important advantages:

  1. Automation interfaces: Because WMI comes with a set of automation interfaces ready to use, all management features supported by a WMI provider and its set of classes get the scripting support for free out-of-the box. Beyond the WMI class design and the provider development, the Microsoft development and test teams are not required to create, validate and test a scripting model as it is already available from WMI.
  2. .NET Management interfaces: Because the System.Management namespace relies on the existing COM/DCOM plumbing, the created WMI provider and its set of WMI classes becomes automatically available to all .NET applications independently of the language used (e.g. C#, VB.NET). Beyond the WMI class design and the provider development, like for scripting, the Microsoft development and test teams are not required to create, validate and test new assemblies to support a new namespace in the .NET Framework as this support is already available from WMI for free.
  3. C/C++ COM/DCOM programming interfaces: Like most components in Windows, COM/DCOM programmers can leverage the features of the provider they develop at the COM/DCOM interfaces level. Like in previous environments (Scripting and .NET Framework), a COM/DCOM consumer just needs to interact with the standard set of WMI COM interfaces to leverage the WMI provider capabilities and its set of supported WMI classes. To make all management information available from the native APIs, the WMI provider developer just needs to interact with a set of pre-defined WMI COM interfaces. This will make the management information available at the WMI COM level automatically. Moreover, the scripting COM interface object model is very similar to the COM/DCOM interface object model, which makes life very easy for developers to be familiar with the scripting experience.
  4. Remoting capabilities over DCOM and SOAP: More than simply offering local COM capabilities, as management is all about remoting, WMI offers the DCOM transport. In addition, SOAP transport will be available in Windows Server 2003 R2 through the WS-Management initiative lead by Microsoft, INTEL, SUN and DELL. This initiative allows to run any scripts remotely or to consume WMI data through a specific set of interfaces handling SOAP requests/responses. The big advantage for the WMI provider developer is when he exposes all his features through WMI, WS-Management can in turn consume that information as well (embedded objects in WMI instances are not supported in R2. It is however a target for Longhorn). All the layering to WS-Management and the mapping of the CIM data model to SOAP comes for free out of the WMI/WS-Management solution. In the event DCOM must be used, implementing DCOM requires the presence of a proxy DLL deployed on each client machine. As WMI is available in the Windows Operating System since Windows 2000, you don’t need deal with these issues either.
  5. Support for Queries: WMI offers support for WQL queries out of the box. This means that if a provider is not designed to support queries, WMI supports it by using an enumeration technique out of your provider. That implies that you get the WQL query support for free.
  6. Eventing capabilities: WMI offers the capability to notify a subscriber for any event it is interested in. WMI uses the WMI Query Language (WQL) to submit WQL event queries and defines the type of events to be returned. The eventing mechanism, with all related call-backs, is part of the WMI COM/DCOM and automation interfaces. Any one writing a WMI provider can have the benefit of this functionality at no cost for his customers. It will be up to the consumer to decide how it wants to consume the management information exposed by the WMI provider and its related set of WMI classes.
  7. Code template generator: To speed up the process of writing a WMI provider including all COM/DCOM interfaces and related definitions, the WMI team developed the WMI ATL Wizard to generate the code template implementing a provider. The code generated is based on the WMI class model initially designed by the developer. The WMI provider developer will be able to interface the pre-defined COM/DCOM interfaces for the WMI provider with its set of native APIs retrieving the management information to expose. The exercise consists in filling the “gaps” in the provider code to create the desired interfacing logic.
  8. Predictability: Predictability is an important concern for our customers because it defines the capability of someone having an experience with a set of interfaces managing a Windows component to apply this knowledge right away, intuitively, to any other manageable Windows component without having relearn everything from ground up. Predictability for a customer is a real gain as it increases the Return of Investment (ROI). A person facing such a situation simply expects things to work the same way based on his previous experience. The constant increase of COM programming/scriptable interfaces has a huge impact on the predictability, as this causes more pain to our customers to automate, manage Windows and leverage their existing knowledge. WMI with CIM address this problem by always exposing the same programming object model (COM/DCOM, Automation, .NET) whatever the manageable entity is.
  9. Protect existing customer investments: Protecting customers and partners investment motivates customers to invest in technologies. As Microsoft did invest a lot these past years in writing WMI providers (more than 80 in Windows Server 2003), customers and partners invested in tools leveraging the WMI capabilities of Windows. Therefore, it is a common sense for them to continue to exploit these capabilities instead of having to use a (new) set of specific interfaces for each Windows manageable component. A specific set of interfaces means having a specific set of agents or in-house developed software based on a new model or set of interfaces especially dedicated to a component or technology. By leveraging the capabilities of WMI today, customers and partners can leverage the work investment made in the past while minimizing their costs in developments, learning curves and new discoveries. This will also have a great impact on the stability and reliability of their infrastructure as they continue to leverage an existing implementation with an improved technology.
  10. Provide a logical and unified administration model: As briefly described before in the introduction, this model is based on an industry standard called CIM defined by the DMTF ( The CIM class-based schema is defined by a consortium of constructors and software developers that meets the requirements of the industry. This implies that not only Microsoft leverages the WMI capabilities, but also any other third party constructors or developers write their own code to fit into the model (For instance, INTEL is doing this for some their network driver adapters and software. HP is leveraging existing WMI providers and implementing their own WMI providers in their HP Open View Enterprise Management software. IBM consumes WMI from the Tivoli management suite, MOM and SMS are also consuming and providing WMI information. Last but not least, WMI XP SP2 is leveraging WMI to get information status from anti-virus software and firewall).

What do you need to work with WMI?[modifier | modifier le wikicode]

From a development perspective, you must run Windows 2000, Windows XP or Windows Server 2003. Visual Studio 2003 or 2005 must be installed on the machine. The latest service pack and fixes are obviously recommended. The Windows machine doesn’t have to be part of any domain unless the provider you plan to develop requires to access information in the domain. For testing purposes the Windows installation can run as a virtual machine with Virtual PC 2004 or Virtual Server 2005 (See for more information).

Note: This document has been written with Visual Studio 2005 Beta 1 (Whidbey). It will be updated when Beta 2. If you use Visual Studio 2003, don’t be surprised if your screen shots don’t match the ones you have in this document.

Some WMI tools can also be very useful during the design and development phases. These tools are:

  • The MOF compiler (MOFCOMP.Exe): The Managed Object Format (MOF) compiler parses a file containing Managed Object Format statements and adds the classes and class instances defined in the file to the CIM repository. The MOF format is a specific syntax to define CIM class representation in an ASCII file (e.g. MIB are to SNMP such as MOF files are to CIM). MOFCOMP.Exe is included in every WMI installation. Every definition existing in the CIM repository is initially defined in a MOF file. MOF files are located in %SystemRoot%\system32\wbem. During the WMI setup, they are loaded in the CIM repository.
  • The WMI Administrative Tools: The WMI Administrative Tools are made of four tools: WMI CIM Studio, WMI Object Browser, WMI Event Registration and WMI Event viewer. You can download these tools from The most important tool for a WMI provider development is WMI CIM Studio as it helps in the initial WMI class creation in the CIM repository. It uses a web interface to display information and relies on a collection of ActiveX components installed on the system when it runs for the first time. WMI CIM Studio provides the ability to:
    • Connect to a chosen system and browse the CIM repository in any namespace available.
    • Search for classes by their name, by their descriptions or by property names.
    • Review the properties, methods and associations related to a given class.
    • See the instances available for a given class of the examined system.
    • Perform Queries in the WQL language.
    • Generate a MOF file based on selected classes.
    • Compile a MOF file to load it in the CIM repository.
  • Winmgmt.Exe: WinMgmt.Exe is not a tool; it is the executable that implements the WMI Core service. Under Windows NT, Windows 2000 and Windows Server 2003, WMI runs as a service. On computers running Windows 98, Windows 95 or Windows Millennium, WMI runs as an application. Under Windows NT, Windows 2000, Windows XP or Windows Server 2003, it is also possible to run this executable as an application, in which case, the executable runs in the current user context. For this the WMI service must be stopped first. The executable supports some switches that can be useful when starting WMI as a service or as an application. WMI provider developers who may want to debug their providers essentially need to run the WMI service as an application.
  • WBEMTEST.Exe: WBEMTEST.Exe is a WMI tester tool, which is delivered in standard with WMI. This tool allows an administrator or a developer to perform most of the tasks from a graphical interface that WMI provides at the API level. Although available under Windows NT, Windows 2000, Windows XP and Windows Server 2003, this tool is not officially supported by Microsoft. Actually, the usage of this tool is not easy at first glance unless you are used to the WMI COM API and the WMI concepts. With WBEMTEST, you can:
    • Enumerate, open, create and delete classes.
    • Enumerate, open, create and delete instances of classes.
    • Select a namespace.
    • Perform data and event queries.
    • Execute methods associated to classes or instances.
    • Execute every WMI operation asynchronously, synchronously or semi-asynchronously.
  • The WMI command line tool (WMIC): WMIC is a command-line tool designed to ease WMI information retrieval about a system by using some simple keywords (aliases). WMIC.Exe is only available under Windows XP Professional and Windows Server 2003. It is not included in other Windows platforms. By typing “WMIC /?” from the command-line, you can obtain a complete list of the switches and reserved keywords available. By typing “WMIC switch-name /?”, you can gather more information about the switch usage.
  • WBEMDUMP.Exe: WBEMDUMP is a tool delivered with the Platform SDK. This command line tool comes with its own Visual C++ project. Basically, the tool can show the CIM repository classes, instances, or both. It is possible to retrieve the same information as that retrieved with WMIC. WBEMDUMP.Exe requires more specific knowledge about WMI, as it doesn’t abstract WMI as WMIC. However, it runs under Windows NT 4.0 and Windows 2000. It is also possible to execute methods exposed by classes or instances. Even if it is not a standard WMI tool delivered with the system installation, this tool can be quite useful for exploring the CIM repository and WMI features.

Comment vérifier que le WMI est bien opérationnel sur la machine[modifier | modifier le wikicode]

Si le WMI est totalement opérationnel sur la machine, alors vous obtiendrez le message "connexion réussie" lors du contrôle du WMI, comme sur cette image : (aller sur "Gestion de l'ordinateur", bouton droit sur Contrôle WMI, puis "Propriétés")

Verif wmi.jpg

Dans le cas contraire, il faudra alors passer au paragraphe "Réparation du WMI"...

Nota : Microsoft propose aussi un outil de vérification du service WMI, en anglais (WMIDiag.exe), et appelé "WMI Diagnosis Utility" : ; cet outil fonctionne actuellement sous Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012 et Windows Server 2012 R2.

Réparation du WMI[modifier | modifier le wikicode]

  • Lancer la réparation sous un compte administrateur.
  • À la fin de la réparation du WMI, il vous faudra aussi procéder à la réparation du « System Center Configuration Manager » (SCCM, anciennement « agent SMS ») si par hasard il était présent sur votre système.

CMD Windows.jpg

Sous Microsoft Windows XP (au moins avec Service Pack 2)[modifier | modifier le wikicode]

Il vous suffira d'ouvrir une fenêtre "DOS" (Démarrer/exécuter/CMD <entrée>), puis de taper les commandes suivantes l'une après l'autre :

  • cd /d %windir%\system32\wbem <entrée>
  • net stop ccmexec /y <entrée>
  • net stop sharedaccess /y <entrée>
  • net stop winmgmt /y <entrée>
  • rd /S /Q repository <entrée>
  • rundll32 wbemupgd, UpgradeRepository <entrée>

Nota : il se peut que certains services tels que CCMEXEC ou SHAREDACCESS n'existent pas sur votre configuration, ça ne posera pas de problème pour la suite de la réparation.

Une fois que la dernière commande de réparation sera terminée, vous reviendrez au prompt. Vous devrez alors procéder à un reboot de l'ordinateur. C'est tout.

Sous Microsoft Windows Server 2003 (au moins avec Service Pack 1)[modifier | modifier le wikicode]

Il vous suffira d'ouvrir une fenêtre "DOS" (Démarrer/exécuter/CMD <entrée>), puis de taper les commandes suivantes l'une après l'autre :

  • cd /d %windir%\system32\wbem <entrée>
  • net stop ccmexec /y <entrée>
  • net stop sharedaccess /y <entrée>
  • net stop winmgmt /y <entrée>
  • rd /S /Q repository <entrée>
  • rundll32 wbemupgd, RepairWMISetup <entrée>

Nota : il se peut que certains services tels que CCMEXEC ou SHAREDACCESS n'existent pas sur votre configuration, ça ne posera pas de problème pour la suite de la réparation.

Une fois que la dernière commande de réparation sera terminée, vous reviendrez au prompt. Vous devrez alors procéder à un reboot de la machine. C'est tout.

Sous Microsoft Windows Vista, Windows 7, Windows 8, Windows 10, Windows Server 2008, Windows Server 2012[modifier | modifier le wikicode]

Il vous faudra lancer l'invite de commande en tant qu'administrateur (clic droit dessus puis sur "exécuter en tant qu'administrateur" pour le faire en mode d'élévation de privilèges). Puis vous taperez les commandes suivantes l'une après l'autre :

  • cd /d %windir%\system32\wbem <entrée>
  • net stop ccmexec /y <entrée>
  • net stop sharedaccess /y <entrée>
  • net stop winmgmt /y <entrée>
  • rd /S /Q repository <entrée>
  • net start winmgmt <entrée>
  • winmgmt /salvagerepository <entrée>

Nota : il se peut que certains services tels que CCMEXEC ou SHAREDACCESS n'existent pas sur votre configuration, ça ne posera pas de problème pour la suite de la réparation.

Une fois que la dernière commande de réparation sera terminée, vous reviendrez au prompt. Vous devrez alors procéder à un reboot de la machine. C'est tout.

Sous autres (anciennes) versions Microsoft Windows[modifier | modifier le wikicode]

Nota : Ca provoquera un reset de la configuration ICS et ICF.

Il vous suffira d'ouvrir une fenêtre "DOS" (Démarrer/exécuter/CMD <entrée>), puis de taper les commandes suivantes l'une après l'autre :

  • winmgmt /clearadap <entrée>
  • winmgmt /kill <entrée>
  • winmgmt /unregserver <entrée>
  • winmgmt /regserver <entrée>
  • winmgmt /resyncperf <entrée>
  • net stop winmgmt /y <entrée>
  • del %windir%\system32\Wbem\Repository\*.* /s <entrée>
  • net start winmgmt <entrée>
  • %windir%\system32\wbem\wbemtest.exe <entrée>

Une fois que la dernière commande de réparation sera terminée, vous reviendrez au prompt. Vous devrez alors procéder à un reboot de la machine. C'est tout.