Gaius Bonus wrote:
> Hello,
> sorry if the question is so stupid as I assume.
> I try to get the size of a file by using wmi (because I want to collect
> the size of various files on Microsoft boxes all over the network
> later).
>
> I try:
>
> require 'win32ole'
> mgmt = WIN32OLE.connect("winmgmts:\\\\.")
> fiNa=mgmt.ExecQuery("SELECT * FROM CIM_DataFile WHERE Name =
> 'c:\\test.txt'")
> fiNa.each {|fn| puts fn.FileSize.to_s}
>
> I do not get any error message but also no output. So I think I do
> something wrong with the wmi handling. I messed arround the whole day
> and now I run out of ideas. It would be great if you could help me.
> Thanks in advance,
> bye
>
>   
\ is a control character in both in WQL and ruby so you need to escape 
the slashes in the query twice:

fiNa=mgmt.ExecQuery("SELECT * FROM CIM_DataFile WHERE Name = 
'c:\\\\test.txt'")

Also, the reason you weren't getting an error message about this seems 
to be related to WMI often being asynchronous. If you had tried
fiNa.Count
it would have thrown an 80041017 error - a syntax error.

BTW I know nothing of WMI, I was just bored, curious, and feeling 
generous so I basically did the googling for you :)

Ken