TechWindows safe removal: Is it still necessary or just a relic?

Windows safe removal: Is it still necessary or just a relic?

If a USB flash drive or an external hard drive is in use when we wish to disconnect it from the computer, Windows will notify us via the safe removal button. However, it doesn’t specify which program is utilising the drive - but it is possible to check this.

How to check what is blocking the safe ejection of the device
How to check what is blocking the safe ejection of the device
Images source: © PxHere
Kamil J. Dudek

23 Jul 2024 | updated: 6 November 2024 17:25

The "safe removal of devices" function has already become the butt of jokes. USB flash drives rarely suffer damage during disconnection, and the warning message sounds disproportionately ominous compared to the consequences. Moreover, the system often cautions against disconnecting the USB even when nothing is using the drive. Safe removal in Windows has become so redundant that many people are unaware of this function and unplug the USB flash drive after use.

Windows has also been optimised for file queuing and cache handling to minimise losses in case of sudden disconnection. Combined with the increase in the speed of solid-state drives, the need to perform a particular operation before detaching the media has practically vanished. The last systems that unconditionally warned the user after unplugging the flash drive without warning were Windows Millennium Edition and Windows 2000. Even XP ceased doing this after one of the Service Packs.

Is it necessary?

Today, we will only receive an error message if we interrupt an unpostponed operation by unplugging or if a program tries to read from a "letter" that has just vanished. Nevertheless, safely removing older devices, platter-based drives, or media or data that we particularly wish to avoid loss/damage can be beneficial.

Today, the safe removal icon uses less pretentious terminology and describes the options for USB flash drives and drives as "ejecting the media." If the ejection is successful, no I/O operations are ongoing, the write cache is synchronized, and no programme is anticipating the presence of the media, which we can then unplug.

A native notification in the bottom right corner of the screen will announce the success of the ejection procedure. However, if a programme is still using the drive, the ejection mechanism will be denied. Windows will then display an archaic window with a format and content reminiscent of Windows 2000. Yet, it doesn’t provide information about which programme vetoed the media ejection.

Let’s use PowerShell

However, this information is available in the system log and can be extracted using Event Viewer and PowerShell. In client versions of Windows, reading this information doesn’t require administrative privileges. To discover which process vetoed the last attempt to eject the media (and which media it was), you should use the following command:

This way, we will obtain the program's name, PID, and the exact name of the blocked device. We can locate and disable the problematic program and try again with this information. Very often, in Windows 11, the program vetoing the ejection request is… Task Manager. Therefore, it is worth closing it before resorting to the terminal and PowerShell commands.

function Get-EjectBlocker { [CmdletBinding()] $msgpcs = New-Object System.Collections.Hashtable 'VetoingDevices','ProcessName','ProcessId' | ` Foreach-Object { ` $a = $_ ; $msgpcs.Add($a ,` (` ( [xml]( ( Get-WinEvent -FilterHashTable ` @{ LogName='System' ProviderName='*Kernel-PnP' ID='225' } -MaxEvents 1 ).ToXml() ) ).Event.EventData.Data | Where-Object ` { $_.Name -eq $a } ).'#text'.ToString().Normalize().Trim() ) } Write-Verbose "Ejecting $($msgpcs.VetoingDevices) is blocked by the process $($msgpcs.ProcessName) ($($msgpcs.ProcessId))." return $msgpcs } Get-EjectBlocker
Related content
© Daily Wrap
·

Downloading, reproduction, storage, or any other use of content available on this website—regardless of its nature and form of expression (in particular, but not limited to verbal, verbal-musical, musical, audiovisual, audio, textual, graphic, and the data and information contained therein, databases and the data contained therein) and its form (e.g., literary, journalistic, scientific, cartographic, computer programs, visual arts, photographic)—requires prior and explicit consent from Wirtualna Polska Media Spółka Akcyjna, headquartered in Warsaw, the owner of this website, regardless of the method of exploration and the technique used (manual or automated, including the use of machine learning or artificial intelligence programs). The above restriction does not apply solely to facilitate their search by internet search engines and uses within contractual relations or permitted use as specified by applicable law.Detailed information regarding this notice can be found  here.