2015-09-13 14:25:48 +0000 2015-09-13 14:25:48 +0000
25
25
Advertisement

如何通过cmd弹出光盘?

Advertisement

我一直在尝试使用cmd. 弹出cd盘,然而,我却陷入了困境。在网上搜索,我只找到了这个答案。

eject D:

还有一个类似的答案

eject D: /I

这两个答案都没有用。

EDIT 现在人们在超级用户上找到了这个答案,

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
colCDROMs.Item(0).Eject

然而,我得到了一个错误。

colCDROMS.Item is not recognized as an internal or external command, operable program or batch file.

Advertisement
Advertisement

答案 (6)

19
19
19
2015-09-13 14:29:11 +0000

你可以用批处理文件弹出一张CD(这是部分vbscript

@echo off
echo Set oWMP = CreateObject("WMPlayer.OCX.7") >> %temp%\temp.vbs
echo Set colCDROMs = oWMP.cdromCollection >> %temp%\temp.vbs
echo For i = 0 to colCDROMs.Count-1 >> %temp%\temp.vbs
echo colCDROMs.Item(i).Eject >> %temp%\temp.vbs
echo next >> %temp%\temp.vbs
echo oWMP.close >> %temp%\temp.vbs
%temp%\temp.vbs
timeout /t 1
del %temp%\temp.vbs

这不是我的作品,我在stackoverflow社区找到的:

帖子链接。批量命令行弹出CD盘? 回答者: Bruno 回答日期:2015年2月10日。2015年2月10日

19
19
19
2015-09-13 17:53:23 +0000

你可以使用Shell.Application COM对象的InvokeVerb方法。在cmd提示符下,你可以这样滥用PowerShell单行代码。

powershell "(new-object -COM Shell.Application).NameSpace(17).ParseName('D:').InvokeVerb('Eject')"

你也可以使用Windows脚本主机(VBScript / JScript)来调用COM对象。下面是一个使用Batch + Jscript混合脚本的例子(用.bat扩展名保存):

@if (@CodeSection == @Batch) @then

@echo off
setlocal

set "CDdrive=D:"

cscript /nologo /e:JScript "%~f0" "%CDdrive%"

goto :EOF

@end // end batch / begin JScript hybrid chimera
var oSH = WSH.CreateObject('Shell.Application');
oSH.NameSpace(17).ParseName(WSH.Arguments(0)).InvokeVerb('Eject');

如果你喜欢让你的脚本检测CD驱动器的驱动字母,也可以这样安排。这里是一个更完整的版本,并对一些非自明的值进行了注释。

@if (@CodeSection == @Batch) @then

@echo off
setlocal

cscript /nologo /e:JScript "%~f0"

goto :EOF

@end // end batch / begin JScript hybrid chimera

// DriveType=4 means CD drive for a WScript FSO object.
// See http://msdn.microsoft.com/en-us/library/ys4ctaz0%28v=vs.84%29.aspx

// NameSpace(17) = ssfDRIVES, or My Computer.
// See http://msdn.microsoft.com/en-us/library/windows/desktop/bb774096%28v=vs.85%29.aspx

var oSH = new ActiveXObject('Shell.Application'),
    FSO = new ActiveXObject('Scripting.FileSystemObject'),
    CDdriveType = 4,
    ssfDRIVES = 17,
    drives = new Enumerator(FSO.Drives);

while (!drives.atEnd()) {
    var x = drives.item();
    if (x.DriveType == CDdriveType) {
        oSH.NameSpace(ssfDRIVES).ParseName(x.DriveLetter + ':').InvokeVerb('Eject');
        while (x.IsReady)
            WSH.Sleep(50);
    }
    drives.moveNext();
}
4
Advertisement
4
4
2015-09-13 14:46:50 +0000
Advertisement

使用WMPlayer.OCX.7会惊动大多数的反病毒程序,而且有些版本的windows是没有媒体播放器的。这里有一个使用shell.application和invokeVerb函数的方法。

.bat扩展名保存:

@cScript.EXE //noLogo "%~f0?.WSF" //job:info %~nx0 %*
@exit /b 0

   <job id="info">
      <script language="VBScript">
        if WScript.Arguments.Count < 2 then
            WScript.Echo "No drive letter passed"
            WScript.Echo "Usage: " 
            WScript.Echo " " & WScript.Arguments.Item(0) & " {LETTER|*}"
            WScript.Echo " * will eject all cd drives"
            WScript.Quit 1
        end if
        driveletter = WScript.Arguments.Item(1):
        driveletter = mid(driveletter,1,1):

        Public Function ejectDrive (drvLtr)
            Set objApp = CreateObject( "Shell.Application" ):
            Set objF=objApp.NameSpace(&H11&):
            'WScript.Echo(objF.Items().Count):
            set MyComp = objF.Items():
            for each item in objF.Items() :
                iName = objF.GetDetailsOf (item,0): 
                iType = objF.GetDetailsOf (item,1): 
                iLabels = split (iName , "(" ) :
                iLabel = iLabels(1):

                if Ucase(drvLtr & ":)") = iLabel and iType = "CD Drive" then
                    set verbs=item.Verbs():
                    set verb=verbs.Item(verbs.Count-4):
                    verb.DoIt():
                    item.InvokeVerb replace(verb,"&","") :
                    ejectDrive = 1:
                    exit function:

                end if
            next    
            ejectDrive = 2:
        End Function

        Public Function ejectAll ()
            Set objApp = CreateObject( "Shell.Application" ):

            Set objF=objApp.NameSpace(&H11&):
            'WScript.Echo(objF.Items().Count):
            set MyComp = objF.Items():
            for each item in objF.Items() :
                iType = objF.GetDetailsOf (item,1):                                 
                if iType = "CD Drive" then
                    set verbs=item.Verbs():
                    set verb=verbs.Item(verbs.Count-4):
                    verb.DoIt():
                    item.InvokeVerb replace(verb,"&","") :
                end if

            next
        End Function
        if driveletter = "*" then 
            call ejectAll
            WScript.Quit 0
        end if
        result = ejectDrive (driveletter):

        if result = 2 then
            WScript.Echo "no cd drive found with letter " & driveletter & ":"
            WScript.Quit 2
        end if

      </script>
  </job>

你可以像这样使用(更多信息-)

call eject.bat *
```。
4
4
4
2016-03-09 13:50:12 +0000

命令行CD-eject oneliner:

在bat文件中或直接在0x6中&第一次运行0x6后就可以了&在Windows 8上:

powershell (New-Object -com "WMPlayer.OCX.7").cdromcollection.item(0).eject()
```。
0
Advertisement
0
0
2016-10-04 12:15:44 +0000
Advertisement

在Windows 10中,我使用这个小脚本。它的工作原理是

dim oWMP
  Set oWMP = CreateObject("WMPlayer.OCX.7")
  Set colCDROMs = oWMP.cdromCollection
  colCDROMs.Item(0).Eject
  set oWMP = nothing
0
0
0
2016-07-13 12:56:48 +0000

如果您可以使用第三方应用程序,您可以使用 Nirsoft的nircmd 。在我试过的所有PC上(从Windows XP到Windows 8),我都可以使用以下方法弹出光盘。

"C:\path_to\nircmd.exe" cdrom open X:

其中X是你的磁盘驱动器字母。

Advertisement

相关问题

3
19
10
28
10
Advertisement
Advertisement