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

Commit ce69c48

Browse files
authored
Fix #97 where EJECT_CDROM won't work on Core edition.
2 parents febd84c + b73381f commit ce69c48

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
@@ -1177,14 +1177,12 @@ function ejectContextCD($cdrom_drive)
11771177
if ($eject_cdrom -ne $null -and $eject_cdrom.ToUpper() -eq 'YES') {
11781178
logmsg '* Ejecting context CD'
11791179
try {
1180-
$disk_master = New-Object -ComObject IMAPI2.MsftDiscMaster2
1181-
for ($cdrom_id = 0; $cdrom_id -lt $disk_master.Count; $cdrom_id++) {
1182-
$disk_recorder = New-Object -ComObject IMAPI2.MsftDiscRecorder2
1183-
$disk_recorder.InitializeDiscRecorder($disk_master.Item($cdrom_id))
1184-
if ($disk_recorder.VolumeName -eq $cdrom_drive.DeviceID) {
1185-
$disk_recorder.EjectMedia()
1186-
break
1187-
}
1180+
#https://learn.microsoft.com/en-us/windows/win32/api/shldisp/ne-shldisp-shellspecialfolderconstants
1181+
$ssfDRIVES = 0x11
1182+
$sh = New-Object -ComObject "Shell.Application"
1183+
$sh.Namespace($ssfDRIVES).Items() | Where-Object { $_.Type -eq "CD Drive" -and $_.Path -eq $cdrom_drive.Name } | ForEach-Object {
1184+
$_.InvokeVerb("Eject")
1185+
logmsg " ... Ejected $($cdrom_drive.Name)"
11881186
}
11891187
} catch {
11901188
logmsg " ... Failed to eject the CD: $_"

0 commit comments

Comments
 (0)