I am running following code:
System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection wmiNetAdapters = wmiNetAdapterConfiguration.GetInstances();
Log.logInfo("Net adapters:" + wmiNetAdapters.get_Count());
And on some machines it is ok, and on some I am getting following error:
System.Management.ManagementException: Not found
Call stack:
System.Management.ManagementException: Not found
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()
Any idea why?
The functionality provided by the System.Management
namespace is dependent upon the WMI (Windows Management Instrumentation) service.
I suspect that the WMI service has not been started on the systems that are throwing that exception.
For troubleshooting purposes, you can verify that using the Administrative Tools → Services utility.
If this turns out to be the case, you can wrap the code in a try
-catch
block and use the ServiceController
class to start and stop the appropriate service.
We just experienced the same problem and followed the below linked post step by step and were able to fix the problem successfully.
https://answers.microsoft.com/en-us/windows/forum/all/systemmanagementmanagementexception-invalid/74ac22c7-509d-42a5-9f7f-2686dc87b7b2
Basically, Open up Computer management and in the sidebar on the left side go to the services and application drop menu and go to WMI control. Then look at the bar on the right and click on more actions and then properties. If you are having the same error as me you will see it here. I tried doing the 'restore from last backup' and it came up with some errors. Then I clicked on 'Restore now'... I had no backups but I saw that the backup files are called '*.rec files'. I went to windows search and searched *.rec and it found one in C:\Windows\System32\wbem . It was called corrupted.rec so I didn't hold much hope, and it seemed as though it came up with the same message as before. So I continued looking around and stuff until I eventually went back to WMI control and saw that it no longer displayed the namespace error but my system spec. After I saw this I opened the software that controls the lights for my laptop and IT OPENED. I have finally been able to turn my god damn obnoxious laptop lights off. After this I made a backup for WMI and I will now make a system restore point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With