I am playing around with WQL today. For a longest time, I couldn’t get this query to work.
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.
This post may contain affiliated links. When you click on the link and purchase a product, we receive a small commision to keep us running. Thanks.
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
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.