win32ole not all methods work

  • Thread starter BG - Ben Armstrong
  • Start date
B

BG - Ben Armstrong

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
#
 
R

rpardee

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

Masaki Suketa

Hello,

In message "win32ole not all methods work"
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
 
B

BG - Ben Armstrong

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
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top