问题描述
亲爱的所有人,
我正在为Windows桌面系统编写应用程序。该应用程序从某些应用程序获取的所有文件句柄中解锁可移动USB驱动器。 br $>
问题:
- 是解锁设备的正确方法。 (见下文)
- 什么是解锁设备的更好方法。
提前致谢。
- Raghav
我尝试了什么:
为此,我使用visual studio编写了一个用C / C ++编写的程序。我使用NtQuerySystemInformation(),NtDuplicateObject(),NtQueryObject()API来获取句柄信息,然后查询句柄对象。如果句柄名称包含设备名称(必须解锁),那么我使用以下方法关闭此句柄 -
BOOL WINAPI DuplicateHandle(
_In_ HANDLE hSourceProcessHandle,
_In_ HANDLE hSourceHandle,
_In_ HANDLE hTargetProcessHandle,
_Out_ LPHANDLE lpTargetHandle,
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ DWORD dwOptions
);
在dwOptions中我使用DUPLICATE_CLOSE_SOURCE,以便源句柄(已锁定设备)关闭,可移动USB设备解锁。
Dear All,
I am writing an application for windows desktop system.This application unlocks a removable USB drives from all the file handles acquired by some applications.
Question:
- Is it right way to unlock the device. (See Below)
- What could be the better way to unlock the device.
Thanks in advance.
-- Raghav
What I have tried:
For this I have written a program in C/C++ using visual studio. I am using NtQuerySystemInformation(), NtDuplicateObject(), NtQueryObject() API to get the handles information and then querying the handle object. If the handle name contains the device name (which has to be unlocked) then I close this handle using the following method-
BOOL WINAPI DuplicateHandle(
_In_ HANDLE hSourceProcessHandle,
_In_ HANDLE hSourceHandle,
_In_ HANDLE hTargetProcessHandle,
_Out_ LPHANDLE lpTargetHandle,
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ DWORD dwOptions
);
And in dwOptions I use DUPLICATE_CLOSE_SOURCE so that the source handle (which has locked the device) gets closed and the removable USB device is unlocked.
推荐答案
这篇关于解锁可移动USB驱动器上的文件句柄...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!