none
ManagementObjectSearcher: ComException Problem RRS feed

  • Question

  • I use ManagementObjectSearcher to determine the existing local windows accounts.

     ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from Win32_Account Where LocalAccount = True AND Status = 'OK' ");
     
     ManagementObjectCollection objects = searcher.Get();
     
     foreach (ManagementBaseObject obj in objects)
     {...}


    The problem is that sometimes a COM-Exception is thrown:

    System.Runtime.InteropServices.COMException
    (0x800706BA) at
    System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at
    System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()

    What could be the reason for this (non deterministic) problem and how can it be solved?

    Tuesday, July 5, 2011 10:04 AM

Answers

  • Hi,

    I have tested your code in my machine. It runs smoothly without any errors or exceptions.

    Add reference->.NET tab->System.Management

    My environment:

    Console.exe/ 64-bit Windows 7/AnyCPU option.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Paul Zhou Monday, July 18, 2011 9:30 AM
    • Marked as answer by Paul Zhou Tuesday, August 9, 2011 1:53 AM
    Thursday, July 7, 2011 9:53 AM