(view source code of ejectcd.vbs as plain text)
Option Explicit
Dim blnFoundCDROM, objCDROMDrive, objDrive, objFSO, objWMP, strCDROM, strMsg
On Error Resume Next
If WScript.Arguments.Named.Count <> 0 Then Syntax
If WScript.Arguments.Unnamed.Count = 1 Then
strCDROM = UCase( WScript.Arguments.Unnamed( 0 ) )
If Len( strCDROM ) > 2 Then
strMsg = "Please specify a CDROM drive to eject."
Syntax
End If
If InStr( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Left( strCDROM, 1 ) ) < 1 Then
strMsg = "Please specify a CDROM drive to eject."
Syntax
End If
If Len( strCDROM ) = 2 And Right( strCDROM, 1 ) <> ":" Then
strMsg = "Please specify a CDROM drive to eject."
Syntax
End If
blnFoundCDROM = False
Set objFSO = WScript.CreateObject( "Scripting.FileSystemObject" )
For Each objDrive In objFSO.Drives
If ( objDrive.DriveLetter = strCDROM Or objDrive.Path = strCDROM ) And objDrive.DriveType = 4 Then
blnFoundCDROM = True
End If
Next
If blnFoundCDROM = False Then
strMsg = "Drive " & Left( strCDROM, 1 ) & ": is not a CDROM drive."
Syntax
End If
Else
strMsg = "Please specify a CDROM drive to eject."
Syntax
End If
Set objWMP = CreateObject( "WMPlayer.OCX.7" )
If Err Then
strMsg = "This script requires Windows Media Player."
Syntax
End If
Set objCDROMDrive = objWMP.cdromCollection.getByDriveSpecifier( strCDROM )
If Err Then
strMsg = "CDROM drive " & strCDROM & " not accessible"
Syntax
End If
objCDROMDrive.Eject
If Err Then
strMsg = "Error ejecting CDROM drive " & strCDROM
Syntax
End If
Sub Syntax
strMsg = strMsg & vbCrLf & vbCrLf & vbCrLf _
& "EjectCD.vbs, Version 1.00" & vbCrLf _
& "Eject a CD-ROM based on a specified drive letter" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT EJECTCD.VBS d:" & vbCrLf & vbCrLf _
& "Where: ""d:"" is the drive letter of the CDROM to be ejected" & vbCrLf & vbCrLf _
& "This script requires Windows Media Player" & vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf
WScript.Echo strMsg
WScript.Quit( 1 )
End Sub
page last modified: 2024-04-16; loaded in 0.0073 seconds