原文是:如何在 Windows NT / Windows 2000/Windows XP 中的弹出可移动媒体
https://support.microsoft.com/zh-cn/kb/165721/zh-cn
是一段应用层的代码,经过编译运行确实弹出了我的U盘,然后我勉强试着将其改为了驱动代码,然后通过编译后,运行出现了问题。
// Do this in a loop until a timeout period has expired
for (nTryCount = 0; nTryCount < LOCK_RETRIES; nTryCount++) {
if (DeviceIoControl(hVolume,
FSCTL_LOCK_VOLUME,
NULL, 0,
NULL, 0,
&dwBytesReturned,
NULL))
return TRUE;
DWORD dwSleepAmount=LOCK_TIMEOUT / LOCK_RETRIES;
int nTryCount;
LARGE_INTEGER Sleeptime=RtlConvertLongToLargeInteger(-10*1000*dwSleepAmount);
// Do this in a loop until a timeout period has expired
for (nTryCount = 0; nTryCount < LOCK_RETRIES; nTryCount++)
{
status = ZwDeviceIoControlFile(hVolume, //status=C00000BB STATUS_NOT_SUPPORTED
NULL,
NULL,
NULL,
&IoStatusBlock,
FSCTL_LOCK_VOLUME,
NULL,
0,
NULL,
0
);
DbgPrint("LockVolume status:%x\n", status);
if (NT_SUCCESS(status))
return TRUE;
放一个在驱动中安全删除硬件的代码附件: usbremove-driver.rar
是根据这个应用层代码改的:原文如何在 Windows NT / Windows 2000/Windows XP 中的弹出可移动媒体
https://support.microsoft.com/zh-cn/kb/165721/zh-cn