3

I try to obtain some system information with several classes from System.Management namespace but any attempt to use ManagementObjectSearcher or ManagementObjectCollection collection items results in FileNotFoundException.

Below I present the problematic piece of code:

    public static string GetProcessorID() {
        var processorID = "";
        var query = "SELECT ProcessorId FROM Win32_Processor";
        var oManagementObjectSearcher = new ManagementObjectSearcher(query);

        foreach (var oManagementObject in oManagementObjectSearcher.Get()) {
            processorID = (string)oManagementObject["ProcessorId"];
            break;
        }

        return processorID;
    }

Exception is thrown in 'foreach' line, when trying to obtain next item from the collection.

It is observed on machine with windows xp professional sp3, with visual studio 2008 professional. I suppose that it can be something with my cpu, which is intel dual core - the same program on other machine with similar environment works perfect. The main difference between those machines is cpu.

Other parameters like MACAddress and SystemDrive provides the same problem, which suggests that it might be rather software issue (WMI?)

Very similar problem is described here -> http://news.softpedia.com/news/XP-SP3-Win32-Processor-Class-Labels-Intel-Core-2-Duo-CPUs-Incorectly-90201.shtml but the solution did not solved it.

Any ideas? Thanks in advance.

Dawid

dawid
  • 190
  • 1
  • 12
  • This makes little sense. How could you ever get the next item from the collection when your loop contains a break statement? – Hans Passant Feb 03 '12 at 02:53
  • Right. Not the next item but the first one. When debugging it stops on 'in' keyword. So I cannot get any item. – dawid Feb 04 '12 at 10:51
  • Not solving your issue, but regardless: do realize that the code will not quite fit for a multi-core, hyperthreaded or multi-processor machine? All of which will produce multiple rows for the query. – Christian.K Jun 15 '12 at 05:13
  • @Eric: No, unfortunately not. I just wrapped this in a try-catch statement, which is not a solution, but in my case it was the only reasonable way to handle the issue. – dawid Jun 26 '12 at 18:55
  • @Christian.K: sounds reasonable but I was getting exception even with other oManagementObject's items, not only "ProcessorId". – dawid Jun 26 '12 at 18:59

2 Answers2

0

I know my answer is a bit late, but because it's the first hit on google when i searched my error i guess i put a link to the topic solving it for me.

System.Management.ManagementException: Not found

Basicly what you have to do is resolve your error's with WMI.

Community
  • 1
  • 1
P. Zantinge
  • 185
  • 1
  • 15
-1

I have the same problem. And it don't crash on 'in word but on

oManagementObjectSearcher.Get().

Check the stack trace:

System.IO.FileNotFoundException - Nie można odnaleźć określonego modułu. (Wyjątek od HRESULT: 0x8007007E)
    Stack trace:
w System.Management.ThreadDispatch.Start()
   w System.Management.ManagementScope.Initialize()
   w System.Management.ManagementObjectSearcher.Initialize()
   w System.Management.ManagementObjectSearcher.Get()
[...]

When I moved to the My computer / right click / manage / services / WMI configration / right click / properties -> I got message that there is an error with message "Win32: Couldn't find module"

Maciej
  • 1