Wie können wir helfen?

WMI Troubleshoot, Repair

Du bist hier:
< Alle Themen

A problem with the WMI may indicate a wide range of errors:

  • The errors on the WMI queries processing in the system and application logs (0x80041002 - WBEM_E_NOT_FOUNDWMI: Not Found0x80041010 WBEM_E_INVALID_CLASS);
  • GPO processing errors related with WMI (incorrect work of the WMI-filters of Group  Policies, etc.);
  • WMI queries are very slow;
  • Errors during installation or operation of SCCM/SCOM agents;
  • Errors in scripts (VBS or PowerShell) that use the WMI namespace (scripts with Get-WmiObject, etc.)

Troubleshooting WMI Problems

The first step is to check the Windows Management Instrumentation (Winmgmt) service is installed on Windows and running. You can check the status of the service in the services.msc console or using PowerShell:

Get-Service Winmgmt | Select DisplayName,Status,ServiceName

check that the Winmgmt service (Windows Management Instrumentation) is running

If the Winmgmt service is running, you can test the health of WMI by quering it with a simple WMI command. You can execute wmi request from command prompt or from PowerShell. For example, the following command will list the programs installed on Windows:

wmic product get name,version

The simplest PowerShell command to get information about the version and build of Windows 10 via WMI might look like this:

get-wmiobject Win32_OperatingSystem

test wmi using powershell cmdlet get-wmiobject

As you can see, the WMI service responded to the request correctly. If Windows returns an error when executing such a WMI query, most likely the WMI service is not working correctly, the WMI repository is damaged, or there are other problems.

wmi error: Failed to initialize all required WMI classes Invalid namespace

In my case, for example, when opening the WMI Control properties in the Computer Management snap-in (compmgmt.msc), the following message appeared:Failed to initialize all required WMI classes Win32_Processor. WMI: Invalid namespace Win32_WMISetting. WMI: Invalid namespace Win32_OperationSystem. WMI: Invalid namespace

Repairing the WMI Repository and Recompiling MOF Files

On Windows 10/Windows Server 2016, you can check the integrity of the WMI repository using the command:

winmgmt /verifyrepository

winmgmt /verifyrepository

If the command returns that the WMI database is in an inconsistent state (INCONSISTENT or WMI repository verification failed), you should try doing a soft fix of WMI repository errors:

Winmgmt /salvagerepositoryWMI repository has been salvaged.

This command checks the consistency of the WMI repository and rebuilds the WMI database if inconsistencies are found.

Restart the WMI service:

net stop Winmgmt
net start Winmgmt

If the standard WMI fix doesn’t work, try the following script. This script is a “soft” option for recovering the WMI service on the computer (the DLL libraries and WMI are re-registered and MOF files are recompiled). This procedure is safe and its implementation should not cause any more problems with the operating system:

sc config winmgmt start= disabled
net stop winmgmt
cd %windir%\system32\wbem
for /f %s in ('dir /b *.dll') do regsvr32 /s %s
wmiprvse /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %s in ('dir /b *.mof') do mofcomp %s
for /f %s in ('dir /b *.mfl') do mofcomp %s

On a 64-bit version of Windows, these steps must also be performed for the SysWOW64 directory. Replace the third line with:

cd %windir%\SysWOW64\wbem

batch script to perform soft reset of the wmi service on windows 10

These commands can be run by simply pasting them into the command prompt, or you can save the script as a BAT file (wmi_soft_repair.bat) and run it with the administrator permissions. After the script finishes, restart Windows and check if WMI is working.

Rebuilding the WMI Repository

If the method described above has not helped, use more “hard” way of the WMI recovery that implies the recreation of the WMI repository.

The WMI repository is located in %windir%\System32\Wbem\Repository and is a database that contains information on the metadata and definitions of the WMI classes. In some cases the WMI repository can also contain static class information. When the repository is damaged, errors occur in the activity of WMI service (Winmgmt).

If you suspect that the WMI repository is damaged, keep in mind that it only should be recreated if no other means to restore WMI are effective.

The following command will reset the WMI database to its original state (as after a clean Windows install). Use this command to hard reset the WMI repository if the salvagerepository parameter didn’t fix the problem:

Winmgmt /resetrepository

Tip. In practice, there are cases, when the rebuilding of WMI repository causes problems with the third-party software. The reason is that all records in the WMI database are cleared (to the state of a clean system). Such software may have to reinstall in recovery mode.

If both commands (Winmgmt /salvagerepository and Winmgmt /resetrepository) didn’t restore the consistent state of the WMI database, try to perform a hard reset of the WMI database with the following script:

sc config winmgmt start= disabled
sc config winmgmt start= disabled
net stop winmgmt
cd %windir%\system32\wbem
winmgmt /resetrepository
winmgmt /resyncperf
if exist Repos_bakup rd Repos_bakup /s /q
rename Repository Repos_bakup
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
for /f %s in ('dir /b *.dll') do regsvr32 /s %s
for /f %s in ('dir /b *.mof') do mofcomp %s
for /f %s in ('dir /b *.mfl') do mofcomp %s
sc config winmgmt start= auto
net start winmgmt
wmiprvse /regserver

bat script to repair or rebuild the WMI Repository on Windows 10

On 64-bit version of Windows, you also need to re-register the DLL/EXE and recompile the MOF files in the %windir%\sysWOW64\wbem directory.

This script completely removes and recreates the WMI repository folder (the old repository is saved to the Repos_backup directory). After the script has completed, you need to restart Windows. Then check the WMI service with a simple query.

Check the WMI repository state. If the errors are fixed, the winmgmt /verifyrepository command should return:WMI repository is consistent

winmgmt /verifyrepository WMI repository is consistent

In this article, we have showed basic ways to diagnose and troubleshoot the WMI service and repository.

Inhaltsverzeichnis