![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #3 (permalink) |
| Guest | RE: how can i eject my cd-rom "9nevermind9" wrote: > is it possible to eject my cd when my program finishes? sure: ############## # start_and_eject.ps1 ############## notepad $processToWatch = get-process notepad $processToWatch.waitforexit() $sa = new-object -com Shell.Application # the next line depends on the language of your Windows # see context menu of the drive (note the '&' for the accelerator key) # english: $sa.Namespace(17).ParseName('D:\').InvokeVerb("E&ject") # german: #$sa.Namespace(17).ParseName('D:\').InvokeVerb("A&uswerfen") ############## -- greetings dreeschkind |
| | #5 (permalink) |
| Guest | Re: how can i eject my cd-rom > is it possible to eject my cd when my program finishes? ie using Media Player OCX : #---8<---Eject_CDS.ps1--- $cds=(New-Object -com 'WMPlayer.OCX').cdromCollection for($i=0;$i -lt $cds.Count;$i++) {$cds.Item($i).Eject()} #---8<---Eject_CDS.ps1--- Regards, -- Jean - JMST Belgium |
| | #6 (permalink) |
| Guest | RE: how can i eject my cd-rom "fixitchris" wrote: > can you elaborate on the meaning of this line... > > $sa.Namespace(17).ParseName('D:\').InvokeVerb("E&ject") Sure. As you can see in the line before, $sa is a variable that contains a COM object("Shell.Application"). This COM object has some methods: $sa | get-member The method Namespace($id) returns a windows shell namespace by that ID. To get all IDs you can use something like this (or websearch for Shell.Application Namespace): 0..61 | ForEach { $sa.Namespace($_).Title + ' : ' + $_ } Ok, now we know that 17 is "My Computer". This Namespace object has some more methods: $sa.Namespace(17) | gm Then we use the "Parse()" method get the right object for your CD/DVD drive (mine is on D:\). $sa.Namespace(17).ParseName('D:\') | gm We see the Method 'Verbs()" which will return all possible actions for this item: $sa.Namespace(17).ParseName('D:\').Verbs() Using the method "InvokeVerb($verbname)" you can trigger that action by name: $sa.Namespace(17).ParseName('D:\').InvokeVerb("E&ject") The web is full of VBscript examples for COM scripting. Most of the scripts can easily be transformed to PowerShell scripts. Some good resources: http://msdn2.microsoft.com/en-us/library/ms630423.aspx http://www.microsoft.com/technet/scr....mspx?mfr=true -- greetings dreeschkind |
| | #7 (permalink) |
| Guest | Re: how can i eject my cd-rom > Using the method "InvokeVerb($verbname)" you can trigger that action by > name: Note here that verbs are localized strings, for this reason it seems to me that the use of wmplayer ocx is more reliable for this action. Regards, -- Jean - JMST Belgium |
| | #8 (permalink) |
| Guest | Re: how can i eject my cd-rom "Jean" wrote: > Note here that verbs are localized strings, for this reason it seems to > me that the use of wmplayer ocx is more reliable for this action. Yeah, I noticed that too (therefore I gave two localized examples in my first post). I'd appreciate it if anyone could tell me how to avoid this localization issue with ".InvokeVerb()". The reason that I like this approach is because you can use this for so much more. You can for instance empty the recycle bin using the right namespace and the right verb. I tried to get the correct localized verb string from the ..Verbs() array first (based on a fixed array index). But the problem is that this order is not fixed because of custom context menu extensions. I agree that the cd eject solution using wmplayer ocx is probably more reliable for this specific action. (If I had known this solution before, then I would have posted this one of course ;-) However, I still think that wmplayer ocx will not work on all windows editions. At least here in Europe Microsoft has been forced to sell "Windows XP N" editions that don't ship with Windows Media Player... -- greetings dreeschkind |
| | #9 (permalink) |
| Guest | Re: how can i eject my cd-rom > "Jean" wrote: > >> Note here that verbs are localized strings, for this reason it seems to >> me that the use of wmplayer ocx is more reliable for this action. > > Yeah, I noticed that too (therefore I gave two localized examples in my > first post). > I'd appreciate it if anyone could tell me how to avoid this localization > issue with ".InvokeVerb()". No localized enumarations are available, so ... Sometimes it could be possible to retrieve a verb name used in the user context by reading some file content (exe,ini, ...). I had done that some times ago ... but I don't remember exaclty what I'd done ... if I retrieve ... > The reason that I like this approach is because you can use this for so much > more. You can for instance empty the recycle bin using the right namespace > and the right verb. I tried to get the correct localized verb string from the > .Verbs() array first (based on a fixed array index). But the problem is that > this order is not fixed because of custom context menu extensions. > Absolutely. It's why this could be only for personal use (or a well known context). And probably more as for security reasons shell.application is often disable by admins. > I agree that the cd eject solution using wmplayer ocx is probably more > reliable for this specific action. (If I had known this solution before, then > I would have posted this one of course ;-) > However, I still think that wmplayer ocx will not work on all windows > editions. At least here in Europe Microsoft has been forced to sell "Windows > XP N" editions that don't ship with Windows Media Player... It's true ... but here I haven't yet seen an XP N box to sell. Reality is imho that nobody want to buy that ... but law is law :-) Regards, -- Jean - JMST Belgium |
| | #10 (permalink) |
| Guest | RE: how can i eject my cd-rom thanks, this example + explanation brightens my view about powerscript. greetings 9nevermind9 "dreeschkind" wrote: > "9nevermind9" wrote: > > > is it possible to eject my cd when my program finishes? > > sure: > > ############## > # start_and_eject.ps1 > ############## > notepad > $processToWatch = get-process notepad > $processToWatch.waitforexit() > > $sa = new-object -com Shell.Application > > # the next line depends on the language of your Windows > # see context menu of the drive (note the '&' for the accelerator key) > > # english: > $sa.Namespace(17).ParseName('D:\').InvokeVerb("E&ject") > > # german: > #$sa.Namespace(17).ParseName('D:\').InvokeVerb("A&uswerfen") > > ############## > > -- > greetings > dreeschkind |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: CD will not eject | PvdG42 | .NET General | 0 | 07-19-2008 10:33 PM |
| Computer won't eject CDs | Gizzy Gizbit | Vista General | 5 | 04-09-2008 05:53 PM |
| CD won't eject !!!!!!!!!! | ttroy | Vista General | 3 | 08-21-2007 11:39 AM |
| Eject a Zip Disk | Mesan | PowerShell | 1 | 07-25-2007 02:08 PM |
| CD Eject Problem | Jassim Rahma | Vista hardware & devices | 3 | 06-24-2006 06:08 PM |