How to check if WMI Query returned 0 rows?

Viewed 260

I'm working on a C# code that is obviously wrong. I'm trying to get a pendrive data with WMI query and after continuing with the operations, check if the query returned 0 rows to avoid bugs.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_USBDevice");
ManagementObjectCollection drive = searcher.Get();
if (drive == null)
{
    MessageBox.Show("Failed to read data.");
    Application.Exit();
}

Obviously the drive == null method does not work. How can I check it the proper way? And also, is this the proper way of getting a pendrive data?

2 Answers
Related