# Using WQL to Limit Results on a String Match



## pcpro17 (Oct 9, 2006)

I'm working on developing a WMI query for my application. It needs to find the assigned virtual COM port for a given VID/PID. My query currently looks like this:


```
"SELECT DeviceID FROM Win32_SerialPort WHERE PNPDeviceID = \"USB\\VID_10C4&PID_EA60\\0001\""
```
Based on my research, it should return "COM8". However, I'm getting an empty set.

Are string comparisons valid in WQL? As I recall, SQL allows them, but being a subset, I'm not sure if support for them was carried over.

If necessary, I suppose I can query `"SELECT DeviceID,PNPDeviceID FROM Win32_SerialPort"` and then in code parse through the results using string compares, but I'd prefer to limit the results in the query, if possible.

Additionally, I was wondering, if string compares are indeed supported in WQL, are they case sensitive, and/or is there a way to specify case?

Thanks.


----------



## TheOutcaste (Aug 8, 2007)

Use Single Quotes in the *Where* clause:

```
"SELECT DeviceID FROM Win32_SerialPort WHERE PNPDeviceID = [COLOR=Red][B]'[/B][/COLOR]USB\\VID_10C4&PID_EA60\\0001\\[COLOR=Red][B]'[/B][/COLOR]""
```
Is the trailing *\* actually present? Might just need *'USB\\VID_10C4&PID_EA60\\0001'*

You can verify it with this:

```
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * FROM Win32_SerialPort")

For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Next
```
Doesn't seem to be Case Sensitive


----------

