[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

WIN32OLE and Shell.Application problem

Eder Quiñones

5/6/2007 12:16:00 AM


Hi, anyone knows what is the problem with this function, i believe i did
everything right, but it just does not open the cd-rom, maybe the
problem is in the part "InvokeVerb". Any help would be highly
appreciated.

def ejectDrives

@wbem = WIN32OLE.new('WbemScripting.SWbemLocator')
@a = @wbem.ConnectServer
@b = @a.InstancesOf('Win32_LogicalDisk')
cdroms = Array.new

@b.each do | object |
if object.Description =~ /cd/i
cdroms << object.Name
end
end

@shell = WIN32OLE.new('Shell.Application')

cdroms.each do | name |

@ej1 = @shell.NameSpace(name)
@ej2 = @ej1.Self
@ej3 = @ej2.InvokeVerb("Expu&lsar")

end

end

This is another version using "WMPlayer.OCX" that actually work.

def ejectDrivesWMP

@wmp = WIN32OLE.new('WMPlayer.OCX')

@cdromCol = @wmp.cdromCollection
@cdromCount = @cdromCol.Count

i = 1
while i <= @cdromCount
@cdromCol.Item(i - 1).Eject
i += 1
end

end

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

3 Answers

David Mullet

5/6/2007 3:57:00 AM

0

On May 5, 8:15 pm, "Eder Quiñones" <eder...@gmail.com> wrote:
> Hi, anyone knows what is the problem with this function, i believe i did
> everything right, but it just does not open the cd-rom, maybe the
> problem is in the part "InvokeVerb". Any help would be highly
> appreciated.
>
> def ejectDrives
>
> @wbem = WIN32OLE.new('WbemScripting.SWbemLocator')
> @a = @wbem.ConnectServer
> @b = @a.InstancesOf('Win32_LogicalDisk')
> cdroms = Array.new
>
> @b.each do | object |
> if object.Description =~ /cd/i
> cdroms << object.Name
> end
> end
>
> @shell = WIN32OLE.new('Shell.Application')
>
> cdroms.each do | name |
>
> @ej1 = @shell.NameSpace(name)
> @ej2 = @ej1.Self
> @ej3 = @ej2.InvokeVerb("Expu&lsar")
>
> end
>
> end
>
> This is another version using "WMPlayer.OCX" that actually work.
>
> def ejectDrivesWMP
>
> @wmp = WIN32OLE.new('WMPlayer.OCX')
>
> @cdromCol = @wmp.cdromCollection
> @cdromCount = @cdromCol.Count
>
> i = 1
> while i <= @cdromCount
> @cdromCol.Item(i - 1).Eject
> i += 1
> end
>
> end
>
> --
> Posted viahttp://www.ruby-....

You might try a variation of the following (where D is the CDROM
drive)...

WIN32OLE.new("Shell.Application").NameSpace(17).ParseName("D:\").InvokeVerb("E&ject")

....or perhaps...

WIN32OLE.new("Shell.Application").NameSpace(17).ParseName("D:\").InvokeVerb("Expu&lsar")

David Mullet
http://rubyonwindows.bl...

Masaki Suketa

5/6/2007 11:49:00 AM

0

Hello,

In message "WIN32OLE and Shell.Application problem"
on 07/05/06, "=?utf-8?Q?Eder_Qui=c3=b1ones?=" <eder.sq@gmail.com> writes:

> cdroms.each do | name |
>
> @ej1 = @shell.NameSpace(name)
> @ej2 = @ej1.Self
> @ej3 = @ej2.InvokeVerb("Expu&lsar")
>

It is known problem.
InvokeVerb does not work in Win32OLE (in Ruby 1.8).
Instead try to use doIt.
@ej1 = @shell.NameSpace(name)
@ej2 = @ej1.Self
verbs = @ej2.verbs
verb = nil
verbs.each do |v|
if v.name == "Expu&lsar"
verb = v
end
end
if verb
verb.doIt
end

FYI, in Ruby 1.9, InvokeVerb works by using WIN32OLE_VARIANT class.

@ej3 = @ej2.InvokeVerb(WIN32OLE_VARIANT.new("Expu&lsar"))

Regards,
Masaki Suketa




David Mullet

5/6/2007 12:35:00 PM

0

On May 6, 7:49 am, Masaki Suketa <masaki.suk...@nifty.ne.jp> wrote:
> Hello,
>
> In message "WIN32OLE and Shell.Application problem"
> on 07/05/06, "=?utf-8?Q?Eder_Qui=c3=b1ones?=" <eder...@gmail.com> writes:
>
> > cdroms.each do | name |
>
> > @ej1 = @shell.NameSpace(name)
> > @ej2 = @ej1.Self
> > @ej3 = @ej2.InvokeVerb("Expu&lsar")
>
> It is known problem.
> InvokeVerb does not work in Win32OLE (in Ruby 1.8).
> Instead try to use doIt.
> @ej1 = @shell.NameSpace(name)
> @ej2 = @ej1.Self
> verbs = @ej2.verbs
> verb = nil
> verbs.each do |v|
> if v.name == "Expu&lsar"
> verb = v
> end
> end
> if verb
> verb.doIt
> end
>
> FYI, in Ruby 1.9, InvokeVerb works by using WIN32OLE_VARIANT class.
>
> @ej3 = @ej2.InvokeVerb(WIN32OLE_VARIANT.new("Expu&lsar"))
>
> Regards,
> Masaki Suketa

Thanks, Masaki!

I was unable to test my earlier code suggestion at the time of
posting. As you say, InvokeVerb does not work as expected, but the
[verb.doIt] method you suggested works well (for me)...

WIN32OLE.new("Shell.Application").NameSpace(17).ParseName("D:\").Verbs.each do |verb|
verb.doIt if verb.Name == "E&ject"
end

Thanks again!

David Mullet
http://rubyonwindows.bl...