ExecutionEngineException using WMI

D

Diablo

Hi,
I am trying to get DeviceType and Serial number of a drive using WMI.

ObjectQuery cmd = new ObjectQuery("select * from Win32_LogicalDisk");
ManagementObjectSearcher search = new ManagementObjectSearcher(cmd);
foreach (ManagementObject vol in search.Get())
{
r = ((UInt32)vol["DriveType"]).ToString() + " " +
(string)vol["VolumeSerialNumber"];
return r;
}

If a run this piece of code in response to a WM_DEVICECHANGE message I
get an ExecutionEngineException in system.management.dll;
otherwise it runs ok!

Any help?
 
W

Willy Denoyette [MVP]

Diablo said:
If i launch the events asynchronously, it works ok! Why?

What do you mean by this? I don't see any events "launched"in you code.
When using System.Management (WMI) you should use event listeners (check
MSDN for ManagementEventWatcher, WqlEventQuery ... ) to handle device
notifications, when using Win32 window notification messages you should use
Win32 API's to handle the events, but never mix both.


Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top