troubleshooting Question

Get drive handle in usermode

Avatar of rayocs
rayocs asked on
StorageSystem Programming
8 Comments1 Solution1335 ViewsLast Modified:
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:
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?

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros