Unable to get WMI object via GETOBJECT ("winmgmts:")

I am at a dead end and cannot find a definitive answer. I am trying to get a list of network adapters through WMI. The team that I use works fine on almost all workstations in our office without any problems. Yesterday the problem. One machine is out of order. Since it runs directly on the user's computer, I do not need to explicitly specify the name of my machine and, therefore, use only "." for the local machine. Then I don't care about β€œwho,” so there is no impersonation. The user should be able to request their own equipment resources. What I used was ...

oWMIService = GETOBJECT("winmgmts:\\.\root\cimv2") oItems = oWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48) 

From what I found, some places say to remove the "\" to refer to the machine path. If I do, MY machine will fail, but there will be no result on the other computer. So, I even tried just going to the root for the service, and that won't work either.

 oWMIService = GETOBJECT("winmgmts:\\.") 

The actual error I get is ...

 Error Code: 0x800401ea: Moniker cannot open file. 

I did a search on this error, but I don’t know how to get permission.

+3
source share
2 answers

Sometimes WMI gets corrupted and confused. Options you could try:

Re-register / recompile the WMI components with the script package as follows:

 net stop winmgmt cd /d %windir%\system32\wbem\ for %i in (*.dll) do RegSvr32 /s %i for %i in (*.mof, *.mfl) do Mofcomp %i net start winmgmt 

If this does not solve the problem, reset the WMI database with this batch:

 net stop winmgmt cd /d %windir%\system32\wbem\ rmdir /s /q Repository rmdir /s /q Logs mkdir Logs net start winmgmt 
And / or try a tool like WMIDiag.vbs script to see if it has any suggestions for you.
+3
source

Please do not use the script above to re-register / recompile WMI components. See this page for more details and a better approach.

0
source

Source: https://habr.com/ru/post/1442321/


All Articles