I'm writing an program to perform auto Safe Removal for all inserted USB drives with a click of a button.
From a MSDN KB that I've found, the recommended step are:
1. Call CreateFile with GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, and OPEN_EXISTING.
2. Lock the volume by issuing the FSCTL_LOCK_VOLUME IOCTL via DeviceIoControl.
3. Dismount the volume by issuing the FSCTL_DISMOUNT_VOLUME IOCTL.
4. Make sure the media can be removed by issuing the IOCTL_STORAGE_MEDIA_REMOVAL IOCTL.
5. Eject the media with the IOCTL_STORAGE_EJECT_MEDIA IOCTL.
6. Close the volume handle obtained in the first step or issue the FSCTL_UNLOCK_VOLUME IOCTL.
The above are working well when I've admin priviledges. Else, all will fail.
I know that the reason is because CreateFile will only return the drive handle with admin priviledge. However, my program needs to work under the limited user mode.
Is there an alternative method to the above or is there a way for me to obtained the drive handle in user mode? Only handles to USB drives are required.
Can any SetupDixxx or CM_xxx functions be used?
Thanks.
No. If you want to obtain a drive handle, your application must run under an account that has admin provileges. But, what is it that you finally want to achieve? Maybe there's a whole different way.