Hello there,
From error code and by the behaviour that it works in admin CMD says that this is related to permission issues in your Win10 IoT 2019 or 2021 LTSC environment.
When you say 'administrative rights,' do you mean an account with admin rights or executed using 'Run As Adminstrator' (UAC)? If the former, you need to do the later.
CM_Request_Device_EjectW() checks to see whether the caller is an interactive process, and is running on the local console session (not a remote winstation).
Try setting SE_LOAD_DRIVER privilege.
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–