System.Management.ManagementException

I run the 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 this is normal, and on some I get the 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?

+6
source share
3 answers

The functionality provided by System.Managementnamespace depends on WMI (Windows Management Instrumentation) .

I suspect that the WMI service was not started on systems that throw this exception.

To troubleshoot, you can verify that you are using the Administration program → Services.

, try - catch ServiceController class, .

+11

, .

https://answers.microsoft.com/en-us/windows/forum/all/systemmanagementmanagementexception-invalid/74ac22c7-509d-42a5-9f7f-2686dc87b7b2

, " " WMI . . . , , . . " ", . " "... , "*.rec files". Windows *.rec, C:\Windows\System32\wbem. corrupted.rec, , , . , WMI , , . , , , . , , . WMI, .

+1

WMI , .

I got exactly the same error and stack trace when I was executing a command using rsconfig.exe, for example

cd C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\

rsconfig.exe -c -s sqlserver\instance -d dbName -a SQL -u user -p pass

What I did wrong is that the instance name has its own argument -i, and this fixed it:

rsconfig.exe -c -s sqlserver -i instance -d dbName -a SQL -u user -p pass

To check the expected arguments, do:

rsconfig.exe /?
0
source

All Articles