System.Management.ManagementException

ぃ、小莉子 提交于 2019-12-04 06:29:39
Cody Gray

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!