From: Masaki Suketa Date: 2005-04-04T21:23:31+09:00 Subject: Re: win32ole not all methods work Hello, In message "win32ole not all methods work" on 05/04/02, BG - Ben Armstrong 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 > # > # 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