What is wrong with next WMi query? (i got "Invalid query" managment exception).
        const string deviceName = "04157DF42C9B1109";
        string wmiQuery = string.Format("SELECT * FROM Win32_USBControllerDevice WHERE Antecedent LIKE '%{0}%'", deviceName);
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
        ManagementObjectCollection retObjectCollection = searcher.Get();
        foreach (ManagementObject retObject in retObjectCollection)
        {
            Console.WriteLine("[{0}]:{1}", retObject["Antecedent"], retObject["Dependent"]);
        }
                I couldn't figure out how to fix the original error but the following approach may be used as a workaround:
string wmiQuery = string.Format("SELECT * FROM Win32_USBControllerDevice");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
var retObjectList = retObjectCollection.Cast<ManagementObject>()
    .Where(m => ((string)m["Antecedent"]).Contains(deviceName))
    .ToList();
foreach (ManagementObject retObject in retObjectList)
{
    Console.WriteLine("[{0}]:{1}", retObject["Antecedent"], retObject["Dependent"]);
}
I noticed other people having the same issue and some people suggested using ASSOCIATORS OF statement (Resource: https://superuser.com/questions/740564/wmi-query-based-on-antecedent-string) That's the accepted answer here so it might just work for you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With