[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Win32OLE CIM_DataFile - ExecQuery fails to match 'Path' property

bmedward

6/8/2006 5:08:00 PM

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.

2 Answers

Chris Hulan

6/8/2006 5:40:00 PM

0

bmedward@gmail.com wrote:

> 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

bmedward

6/8/2006 6:43:00 PM

0

Sweet
The escapes need escaped!

Thanks for the feedback!



ChrisH wrote:
> bmedward@gmail.com wrote:
>
> > 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