Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Получение HANDLE дискового устройства с правами по


Автор: korbian 8.8.2013, 14:40
Не удается получить HANDLE дискового устройства (USB Flash накопитель) с правами пользователя, Windows XP.
Код

hDevice = CreateFile(path.c_str(),
            GENERIC_READ | GENERIC_WRITE, 
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            0,
            OPEN_EXISTING, 0, 0); 

hDevice устанавливается в INVALID_HANDLE_VALUE, GetLastError возвращает 5 (ACCESS DENIED) 
пробовал два варианта, в path:
1. \\?\usbstor#disk&ven_ooo_romashka&prod_mass_storage&rev_1.00#00000000&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}
DevicePath полученный перебором устройств по GUID_DEVINTERFACE_DISK.
2. \\.\f: путь к диску USB Flash накопителя.
Под администратором оба варианта работают исправно. Понимаю, что не хватает прав для осуществления этого действия.

Коллеги, подскажите, пожалуйста какие права необходимо пользователю дать?
из msdn
Цитата

Physical Disks and Volumes
Direct access to the disk or to a volume is restricted. For more information, see "Changes to the file system and to the storage stack to restrict direct disk access and direct volume access in Windows Vista and in Windows Server 2008" in the Help and Support Knowledge Base at http://support.microsoft.com/kb/942448.
Windows Server 2003 and Windows XP:  Direct access to the disk or to a volume is not restricted in this manner.
You can use the CreateFile function to open a physical disk drive or a volume, which returns a direct access storage device (DASD) handle that can be used with the DeviceIoControl function. This enables you to access the disk or volume directly, for example such disk metadata as the partition table. However, this type of access also exposes the disk drive or volume to potential data loss, because an incorrect write to a disk using this mechanism could make its contents inaccessible to the operating system. To ensure data integrity, be sure to become familiar with DeviceIoControl and how other APIs behave differently with a direct access handle as opposed to a file system handle.
The following requirements must be met for such a call to succeed:
The caller must have administrative privileges. For more information, see Running with Special Privileges.
The dwCreationDisposition parameter must have the OPEN_EXISTINGflag.
When opening a volume or floppy disk, the dwShareMode parameter must have the FILE_SHARE_WRITEflag.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)