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.
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.
The WMI Service was running for me and I was using a Administrator account.
I got the exact same error and stacktrace when I was running a command using rsconfig.exe, eg
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 was doing wrong was 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 run:
rsconfig.exe /?
Update:
This is actually incorrect, if you look at the expected arguments it states the server name has to include the instance name as well, you can't have quotes and if the instance name contains a $ sign you may need to escape it, see here for more info: https://stackoverflow.com/a/56370766/495455
来源:https://stackoverflow.com/questions/5247659/system-management-managementexception