Simpler Method: Windows (10 at least) creates an entry in the event log when you try to eject a removable drive and you cannot because a process has a lock on it. One entry shows the process ID and the other the name of the process responsible for the lock.
1) Start the event viewer
2) Open up "Windows Logs" then "System"
3) Right click on "System" and choose "Filter Current Log"
4) In the dialog that comes up, enter "225" (without quotes) where it says "All Event IDs"
5) You will then see all events related to unable to eject because a process locked the drive.
6) Look at the timestamps on all these entries and find out which ones relate to the actual time when you tried to eject the drive.
7) Take appropriate action. Ending a task gracefully (closing the program that has the lock) is OK most of the time. Stopping the Windows Search service is also ok. Stopping an antivirus scan should be ok (if you don't suspect you have any viruses at the time). Going into the task manager and killing the process might not be ok. How to deal with this is beyond the scope of this question.