Identify CD drive and eject using bat or vbs while in WinPE without external files

淺唱寂寞╮ 提交于 2019-12-11 05:09:07

问题


I need to identify the CD drive and eject the tray. This is executed while booted in WinPE, so the WMP eject function is not available. This script will be used on various computer models/configurations. I'm currently using this:

For Each d in CreateObject("Scripting.FileSystemObject").Drives
    CreateObject("Shell.Application").Namespace(17).ParseName("D:\").InvokeVerb("Eject")
Next

It works, but sometimes it errors and requires user interaction before it ejects. I suspect that it's because of the hardcoded D:\ drive letter, but I could be completely wrong. I need this to work without 3rd party utilities.


回答1:


Use the DriveType property of the Drive object:

For Each d in CreateObject("Scripting.FileSystemObject").Drives
    WScript.sleep 60
    If d.DriveType = 4 Then
        CreateObject("Shell.Application").Namespace(17).ParseName(d.DriveLetter & ":\").InvokeVerb("Eject")
    End If
Next



回答2:


Here is code that uses Media Player to eject; I'm not sure how easy it would be to invoke from your WinPE environment:

' http://www.msfn.org/board/topic/45418-vbscript-for-openingclosing-cd/ 
' http://waxy.org/2003/03/open_cdrom_driv/
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection
     For d = 0 to colCDROMs.Count - 1
           colCDROMs.Item(d).Eject 
Next 'null

Plan B would be to download a copy of "eject.exe", and include it on your WinPE media:

  • http://www.911cd.net/forums/index.php?showtopic=2931&hl=cd+eject


来源:https://stackoverflow.com/questions/14220273/identify-cd-drive-and-eject-using-bat-or-vbs-while-in-winpe-without-external-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!