troubleshooting Question

Get drive handle in usermode

Avatar of rayocs
rayocs asked on
System ProgrammingStorage
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:
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.
ASKER CERTIFIED SOLUTION
alexcohn

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 8 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 8 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004