문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top