[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

win32ole not all methods work

BG - Ben Armstrong

4/1/2005 7:54:00 PM

Can someone explain what's going on here, and if there is a fix? Looks
like certain methods don't work, maybe because the type of object
returned isn't known.

require 'win32ole'

WIN32OLE.new('Scripting.FileSystemObject').Drives.each{|drive|
p [drive.driveLetter,drive.driveType,drive.shareName,drive.isReady,drive.path]}

# Generates:
#
# ["A", 1, "", false, "A:"]
# ["C", 2, "", true, "C:"]
# ["D", 4, "", false, "D:"]
# ["F", 3, "\\\\ntfs\\data", true, "F:"]
# ["H", 3, "\\\\ntfs\\users", true, "H:"]
# ["R", 3, "\\\\dyma\\r", true, "R:"]
# ["S", 3, "\\\\dyma\\s", true, "S:"]
# ["T", 3, "\\\\ntfs\\sales", true, "T:"]
# ["U", 3, "\\\\ntfs\\goldmine_ver4.0", true, "U:"]
# ["V", 3, "\\\\ntfs\\apps", true, "V:"]
# ["W", 2, "", true, "W:"]
# ["Y", 3, "\\\\Ntfs\\Data\\Medianet\\SRED", true, "Y:"]
# ["Z", 3, "\\\\NTFS\\users\\dm", true, "Z:"]


WIN32OLE.new('Scripting.FileSystemObject').Drives.each{|drive|
p [drive.driveLetter,drive.driveType,drive.shareName,drive.isReady,drive.path,drive.serialNumber]}

# Generates:
#
# C:/Work/diskid.rb:4:in `method_missing': serialNumber (WIN32OLERuntimeError)
# OLE error code:800A0047 in <Unknown>
# <No Description>
# HRESULT error code:0x80020009
# Exception occurred from C:/Work/diskid.rb:4
# from C:/Work/diskid.rb:3:in `each'
# from C:/Work/diskid.rb:3
#


3 Answers

rpardee

4/1/2005 9:53:00 PM

0

Both of those are working for me. I'm on win2k & WSH 5.6. What
version of WSH are you using?

Masaki Suketa

4/4/2005 12:24:00 PM

0

Hello,

In message "win32ole not all methods work"
on 05/04/02, BG - Ben Armstrong <BArmstrong@dymaxion.ca> writes:

> Can someone explain what's going on here, and if there is a fix? Looks
> like certain methods don't work, maybe because the type of object
> returned isn't known.
>
> WIN32OLE.new('Scripting.FileSystemObject').Drives.each{|drive|
> p [drive.driveLetter,drive.driveType,drive.shareName,drive.isReady,drive.path,drive.serialNumber]}
>
> # Generates:
> #
> # C:/Work/diskid.rb:4:in `method_missing': serialNumber (WIN32OLERuntimeError)
> # OLE error code:800A0047 in <Unknown>
> # <No Description>
> # HRESULT error code:0x80020009
> # Exception occurred from C:/Work/diskid.rb:4
> # from C:/Work/diskid.rb:3:in `each'
> # from C:/Work/diskid.rb:3
> #

It seems to me the correct behavier.

The following VBScript returns the runtime exception.

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
For each drive in fso.Drives
WScript.Stdout.WriteLine drive.driveLetter
WScript.Stdout.WriteLine drive.driveLetter
WScript.Stdout.WriteLine drive.driveType
WScript.Stdout.WriteLine drive.shareName
WScript.Stdout.WriteLine drive.isReady
WScript.Stdout.WriteLine drive.path
' The following line returns the runtime exception.
WScript.Stdout.WriteLine drive.serialNumber
Next

I think drive.isReady is false then, drive.serialNumber raise runtime
exception in VBScript.
And If, the VBScript raise the runtime exception, the Ruby script raise the
runtime exception in the similarly.
So, the following Ruby script as same as above sample,
raise Exception in drive.serialNumber.

require 'win32ole'
WIN32OLE.new('Scripting.FileSystemObject').Drives.each{|drive|
p drive.driveLetter
p drive.driveType
p drive.shareName
p drive.isReady
p drive.path
p drive.serialNumber # occur Exception if drive.isReady is false.
}

In my environment, if the drive is floppy drive or CDROM drive, then
occur the exception.

So,
> # C:/Work/diskid.rb:4:in `method_missing': serialNumber (WIN32OLERuntimeError)
(snip)
> # Exception occurred from C:/Work/diskid.rb:4
is correct behavior.

Regards,
Masaki Suketa



BG - Ben Armstrong

4/4/2005 4:13:00 PM

0

On Mon, 2005-04-04 at 21:23 +0900, Masaki Suketa wrote:
> I think drive.isReady is false then, drive.serialNumber raise runtime
> exception in VBScript.

Excellent. Thanks. Adding an if drive.isReady to our code filters out
the floppy & CD-ROM (which we weren't interested in anyway) thereby
fixing our code.

Ben