Win32OLE CIM_DataFile - ExecQuery fails to match 'Path' property

B

bmedward

I am running ruby 1.8.4 (2005-12-24) [i386-mswin32] and am attempting
to re-write some maintaince scripts from VBScript to Ruby. In doing
so, I have run into a hangup with how Ruby is treating an ExecQuery
statment - whenever I include a 'Path' in the query, I get an empty
collection. Is there a known problem that I am encountering here, or
perhaps a better way that I can utilize this parameter?

Here is an example that fails for me.

1. require 'win32ole'
2. myComputer = "."
3. strSQLQuery = " Select * from CIM_DataFile WHERE Drive = 'C:' AND
Path = '\\' "
4. objWMIService =
WIN32OLE.connect("winmgmts:{impersonationLevel=impersonate}!//#{myComputer}/root/cimv2")
5. colFiles = objWMIService.ExecQuery(strSQLQuery)
6.
7. colFiles.each do |file|
8. puts file.Drive + file.Path + file.FileName + "." +
file.Extension
9. end

If I replace the query with:
"Select * from CIM_DataFile WHERE Drive = 'C:' AND Extension = 'rb' "
All works as expected. Also note that the 'Path' attribute can be read
without error.
 
C

ChrisH

3. strSQLQuery = " Select * from CIM_DataFile WHERE Drive = 'C:' AND
Path = '\\' "
Try Path = '\\\\'

Looks like the query needs two slashes (probably to escape the single)
which requires you to eascape two in Ruby, thus the four slashes are
needed.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top