Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > WMI usage in Ruby to get file size, beginners question

Reply
Thread Tools

WMI usage in Ruby to get file size, beginners question

 
 
Gaius Bonus
Guest
Posts: n/a
 
      11-30-2006
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ken Allen
Guest
Posts: n/a
 
      11-30-2006
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

 
Reply With Quote
 
 
 
 
Gaius Bonus
Guest
Posts: n/a
 
      11-30-2006
Ken Allen wrote:
> Gaius Bonus wrote:
>> 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


Hello Ken,
thanks for the help, it was the hint. As I wrote I'm a beginner and I'm
not yet used to the specifics of everything. Ofcourse I also googled
before I asked but I did not find the \\\\.
thanks again
bye

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby(and programming) beginners question regarding 'NoMethodError'while using Hpricot Sandeep Guria Ruby 5 02-25-2011 09:33 AM
[Update] Ruby Zen: Ruby for Beginners Phillip Gawlowski Ruby 0 01-22-2010 09:52 PM
Error Using WMI to Get List of Shared Folders on the Server lecnac ASP .Net 1 04-21-2006 08:36 PM
Get Default printer WMI =?Utf-8?B?V2lsbGVt?= ASP .Net 2 12-07-2004 02:06 AM
Using perl and wmi to get MS file version info kngnsm Perl Misc 0 08-24-2004 11:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57