Fixing problems with WMISometimes (rarely though) you will have a case where the WMI repository gets corrupted, and when you have a script that attempts to run, you get a Null Exception or something like that. Anyway, that's what I got a couple of times today when I deployed a script that applies a few registry changes using the root\default:StdRegProv class, and I got a couple of reports of it erroring. I didn't initially know any better, but I thought that maybe the StdRegProv class didn't exist in Windows XP SP1 (hence the Null Reference), but that wasn't the case, because it worked on some other SP1 machines. It wasn't until I tried connecting to the root\cimv2 namespace on the couple of affected machines that I understood what was going on; the WMI repository was corrupt. Here's a quick way of testing if there's a problem with WMI:
Goto Start --> Run ... --> type wbemtest --> hit Enter
In the Tester utility, press Connect
Type root\cimv2 in the top-left box where by default it says root\default
Press Enter
At this point, if you get an error saying Invalid Namespace or This Operation is Not Supported, or anything to that effect, chances are that you have a problem with the WMI repository. The reason for this, is that the root\cimv2 is what you could call the "primary" namespace of WMI, or the one that provides the most information about your system; If this namespace isn't working, it's likely that none of them are. Now, here's the steps you can take to actually fix the problem:
Refresh the WMI Repository
Goto Start --> Run ... --> type net stop winmgmt --> press enter
Input Y, if prompted --> press Enter
Open Windows Explorer ([Windows] + E, keyboard shortcut) and navigate to %WINDIR%\System32\wbem\repository
Delete all the contents of the wbem\repository folder
Goto Start --> Run ... --> type net start winmgmt --> press enter
Test the WMI Repository
Goto Start --> Run ... --> type wbemtest --> press enter
Press the connect button
Type root\cimv2 in the upper-left box
Press Enter
At this point, your computer may hesitate for a moment while it rebuilds the WMI repository. Remember, after you delete the repostiory and restart the service, WMI doesn't rebuild the repository until you actually use the WMI service. From this point forward, your problems ought to be resolved and you can go on scripting (or programming) happily :-)
¶ 5:11 PM