locked
WMI basic sample throws exception RRS feed

  • Question

  • I am trying to start using WMI with C#, but the simplest sample from MSDN throws exception during run. The sample is below, the problem is

    searcher.Get()

    throws exception "Not found". Any clues?

    class

    Query_SelectQuery
    {
    publicstaticint Main(string[] args)
    {
    WqlObjectQuery wqlQuery =newWqlObjectQuery("SELECT * FROM Win32_LogicalDisk");
    ManagementObjectSearcher searcher =newManagementObjectSearcher(wqlQuery);

    foreach

    (ManagementObject diskin searcher.Get())
    {

    Console

    .WriteLine(disk.ToString());
    }
    }
    }

    Thursday, April 15, 2010 12:59 AM

Answers

  • Hello ValJ,

    Sorry for late responsing, I have built a Windows XP SP2 test machine. When I run the codes from VS 2008 SP1, I still cannot reproduce the issue. No exception is thrown. I got my A, C, D logical disk.

    I think the issue could be hardware related. Could you please use the WMI Adminitrative Tool to see if you can use the tool to directly observe the Win32_LogicalDisk object,

    1.Download and install the tool from, http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en

    2.Start the tool WMI Object Browser tool.

    3.In the left panel, click the Browse for Instance button

    4.In the Available classes textbox, input Win32_LogicalDisk

    5.Click Add button, and click OK button.

    6.Then, we should be able to see the results of all LogicalDisks.

    If the tool also cannot observe the disks, that probably means the issue is hardware or driver specific.

     

    Best regards,
    Ji Zhou
    MSDN Subscriber Support in Forum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Ji.Zhou Friday, April 23, 2010 2:04 AM
    Wednesday, April 21, 2010 8:36 AM

All replies

  • Cannot reproduce the error.

    I use exactly the same codes and run it in my Visual Studio 2010 and Windows 7 system.

    I get the expected all logical disks,

    \\COLBERTZ2\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
    \\COLBERTZ2\root\cimv2:Win32_LogicalDisk.DeviceID="D:"
    \\COLBERTZ2\root\cimv2:Win32_LogicalDisk.DeviceID="E:"
    \\COLBERTZ2\root\cimv2:Win32_LogicalDisk.DeviceID="Z:"

    What is the exact error code and message in your side? And what OS system you are running on?

     

    Best regards,

    Ji Zhou

    MSDN Subscriber Support in Forum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, April 15, 2010 11:01 AM
  • I am using WindowsXP SP2, running the code from VS2008SP1. I have a C: (HD), D: (DVD).

    Here is the complete exception info:

    Management exception: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.ManagementObjectSearcher.Initialize()
       at System.Management.ManagementObjectSearcher.Get()
       at WMIClient.Query_SelectQuery.Main(String[] args) in C:\Development\WMI\WMIClient\WMIClient\Program.cs:line 21

    Val

     

    Friday, April 16, 2010 5:51 PM
  • Hello ValJ,

    Sorry for late responsing, I have built a Windows XP SP2 test machine. When I run the codes from VS 2008 SP1, I still cannot reproduce the issue. No exception is thrown. I got my A, C, D logical disk.

    I think the issue could be hardware related. Could you please use the WMI Adminitrative Tool to see if you can use the tool to directly observe the Win32_LogicalDisk object,

    1.Download and install the tool from, http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en

    2.Start the tool WMI Object Browser tool.

    3.In the left panel, click the Browse for Instance button

    4.In the Available classes textbox, input Win32_LogicalDisk

    5.Click Add button, and click OK button.

    6.Then, we should be able to see the results of all LogicalDisks.

    If the tool also cannot observe the disks, that probably means the issue is hardware or driver specific.

     

    Best regards,
    Ji Zhou
    MSDN Subscriber Support in Forum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Ji.Zhou Friday, April 23, 2010 2:04 AM
    Wednesday, April 21, 2010 8:36 AM
  • Hi Guys

    This issue has been affecting me recently.  It affects trying to retrieve data from WMI, and affects a couple of tables I tried.

    The solution was that the WMI database was corrupted and needed to be rebuilt.

     

    Monday, May 16, 2011 11:43 AM
  • Yes it happened to me as well. As the previosu post suggests, I had to rebulid the WMI database to resolve the issue. I followed this article to rebuild the database http://www.ehow.com/how_5829585_fix-wmi-errors-vista.html

     

    Saturday, October 15, 2011 2:38 AM