System.Management.ManagementException

前端 未结 3 1185
梦如初夏
梦如初夏 2021-01-05 12:24

I am running following code:

System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass(\"Win32_NetworkAdapterConf         


        
相关标签:
3条回答
  • 2021-01-05 13:03

    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.

    0 讨论(0)
  • 2021-01-05 13:14

    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.

    0 讨论(0)
  • 2021-01-05 13:14

    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

    0 讨论(0)
提交回复
热议问题