Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit b73381f

Browse files
Fix #97 where EJECT_CDROM won't work on Core edition.
Signed-off-by: Jānis Veinbergs <j.veinbergs@gmail.com>
1 parent d6c362e commit b73381f

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/context.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,12 @@ function ejectContextCD($cdrom_drive)
12071207
if ($eject_cdrom -ne $null -and $eject_cdrom.ToUpper() -eq 'YES') {
12081208
logmsg '* Ejecting context CD'
12091209
try {
1210-
$disk_master = New-Object -ComObject IMAPI2.MsftDiscMaster2
1211-
for ($cdrom_id = 0; $cdrom_id -lt $disk_master.Count; $cdrom_id++) {
1212-
$disk_recorder = New-Object -ComObject IMAPI2.MsftDiscRecorder2
1213-
$disk_recorder.InitializeDiscRecorder($disk_master.Item($cdrom_id))
1214-
if ($disk_recorder.VolumeName -eq $cdrom_drive.DeviceID) {
1215-
$disk_recorder.EjectMedia()
1216-
break
1217-
}
1210+
#https://learn.microsoft.com/en-us/windows/win32/api/shldisp/ne-shldisp-shellspecialfolderconstants
1211+
$ssfDRIVES = 0x11
1212+
$sh = New-Object -ComObject "Shell.Application"
1213+
$sh.Namespace($ssfDRIVES).Items() | Where-Object { $_.Type -eq "CD Drive" -and $_.Path -eq $cdrom_drive.Name } | ForEach-Object {
1214+
$_.InvokeVerb("Eject")
1215+
logmsg " ... Ejected $($cdrom_drive.Name)"
12181216
}
12191217
} catch {
12201218
logmsg " ... Failed to eject the CD: $_"

0 commit comments

Comments
 (0)