How can I reconstruct the WMI classes?

How can I reconstruct the WMI classes?

Managed Object Format (MOF) files define the Windows Management Instrumentation (WMI) classes stored in the WMI repository. If the repository becomes corrupted or the WMI class definitions are damaged, WMI queries may fail or return incomplete data, resulting in monitoring failures.

This article explains how to repair or rebuild the WMI repository on the target Windows server.

NotesNote: Rebuilding the WMI repository should be performed only if repairing the repository does not resolve the issue.

Rebuild the WMI Repository

Step 1: Stop the WMI Service

Disable and stop the Windows Management Instrumentation service.


Step 2: Back Up the Existing Repository

Create a backup of the following directory:

Info
C:\%windir%\System32\wbem\Repository

Step 3: Re-register WMI Components

  1. Open Command Prompt with Run as Administrator.
  2. Navigate to the following directory:
Quote
cd C:\%windir%\System32\wbem
  1. Execute the following commands one by one:
Quotefor /f %s in ('dir /b /s *.dll') do regsvr32 /s %s
for /f %s in ('dir /b /s *.mof') do mofcomp %s
for /f %s in ('dir /b /s *.mfl') do mofcomp %s

Step 4: Start the WMI Service

Enable and start the Windows Management Instrumentation service.

NotesNote: If required, replace %windir% with the appropriate Windows installation directory for your operating system.
Operating SystemWindows Directory
Windows 2000winnt
Windows XP, Windows Server 2003, Windows Server 2008windows
Other Windows versionsWindows

Verify the WMI Repository

  1. Open Command Prompt with Run as Administrator.
  2. Execute the following command:
Quote
winmgmt /verifyrepository

Result Interpretation

If the following message is displayed:

Info
WMI Repository is consistent

the repository is healthy, and the issue is likely caused by another WMI component.

If any other message is returned, continue with the repair steps below.


Repair the WMI Repository

Step 1: Attempt to Repair the Repository

Run the following command:

Quote
winmgmt /salvagerepository

If the repair is successful, verify whether the monitoring issue has been resolved.


Step 2: Reset the Repository (if Repair Fails)

If the previous command does not resolve the issue:

  1. Stop the Windows Management Instrumentation service.
  2. Execute the following command:
Quote
winmgmt /resetrepository

If the reset is successful, the following message is displayed:

Info
WMI Repository has been reset


  1. Start the Windows Management Instrumentation service.
  2. Verify that WMI queries execute successfully.

Additional commands for older Windows versions

Windows Server 2003

Execute the following commands:

Quote
wmiadap /f
lodctr /R

Windows 2000 / Windows XP

Execute the following commands:

Quote
winmgmt /clearadap
winmgmt /kill
winmgmt /regserver
winmgmt /resyncperf

Verification

After repairing or rebuilding the repository:

  • Verify that the Windows Management Instrumentation service is running.
  • Execute the required WMI query using WBEMTest.
  • Retry adding the monitor or perform a manual poll of the reported monitor, and verify that data is collected successfully.
  • Confirm that the reported WMI error is no longer observed.

Microsoft References

For additional information, refer to the following Microsoft article: