WQL and Path

I am playing around with WQL today. For a longest time, I couldn’t get this query to work.

If you’re thinking about purchasing a new GPU, we’d greatly appreciate it if you used our Amazon Associate links. The price you pay will be exactly the same, but Amazon provides us with a small commission for each purchase. It’s a simple way to support our site and helps us keep creating useful content for you. Recommended GPUs: RTX 5090, RTX 5080, and RTX 5070. #ad

Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile" &  _

   " WHERE Drive = 'c:' AND Extension = 'mdb' And Path = '\\windows\\' ")

Have you noticed anything wrong with the query? It’s the Path! I found that you need to use double back slash instead of single back slash. So, the correct Query should be like this.

Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile" &  _

   " WHERE Drive = 'c:' AND Extension = 'mdb' And Path = '\\\\windows\\\\' ")

Also, I found that if you have “!=” in your query, the query runs very very slowly.

2 Comments

  1. This is a very poor example, since the correct query matches the incorrect query. To limit the results of your WQL, the CIM_DataFile path should always start with \\ and end with \\. For example:

    SELECT * FROM CIM_DataFile WHERE Drive = ‘c:’ AND Path = ‘\\WindowsOSDir/System32/narkissos\\’

    As you can see, the path must contain the double \\ at the beginning & end or else WBEMTEST will reject it. At this point you could add other criteria to your WQL i.e.: extension, etc.

    Use the force – read your source.

    mark@narkissos.net

  2. Thanks for pointing that out. The blog was created using a different system and when it got imported to WordPress, the back slashes were all gone. I corrected it. It’s OK now.

Leave a Reply