找出哪个进程在USB设备句柄上具有排他锁 [英] Find out which process has an exclusive lock on a USB device handle

查看:123
本文介绍了找出哪个进程在USB设备句柄上具有排他锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用CreateFile()API读写USB设备的库。该设备恰好实现了HID设备配置文件,因此与Microsoft的HID类驱动程序兼容。



系统上安装的某些其他应用正在以读取/没有共享模式的写模式。这会阻止我的媒体库(以及占用它的所有资源)与设备一起使用。我想这是与HID兼容的设备的原因-其他驱动程序软件(鼠标,控制器,PHIDGETS等)可能无法配合使用。



无论如何,设备文件路径的格式为:

 
1: \\?hid#hpqremhiddevice&col01#5&21ff20e7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}。

2: \\hid#vid_045e&pid_0023#7&34aa9ece&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}。

3: \hid#vid_056a&pid_00b0&col01#6&5b05f29&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}。

我正在尝试使用代码打开它,例如:

  //首先,以最小权限打开它,此设备可能不是我们的设备。 
//我们稍后将以读/写方式重新打开它
hid_device_ref = CreateFile(
device_path,GENERIC_READ,
0,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,空值);

我考虑过SysInternals的FileMon或Process Monitor之类的工具。但是我似乎无法报告上面列出的设备文件句柄的使用情况。

解决方案

您尝试过吗是来自sysinternals的句柄

无论如何,两个窗口都不会这样做(显示锁定设备的应用程序的名称):当您尝试弹出USB设备时,Windows只是说该设备正在使用中,无法删除。现在。


I have a library that reads/writes to a USB-device using CreateFile() API. The device happens to implement the HID-device profile, such that it's compatible with Microsoft's HID class driver.

Some other application installed on the system is opening the device in read/write mode with no share mode. Which prevents my library (and anything that consumes it) from working with the device. I suppose that's the rub with being an HID-compatible device -- other driver software (mice, controllers, PHIDGETS, etc) can be uncooperative.

Anyway, the device file path is of the form:

1: "\\?\hid#hpqremhiddevice&col01#5&21ff20e7&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}".

2: "\\?\hid#vid_045e&pid_0023#7&34aa9ece&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}".

3: "\?\hid#vid_056a&pid_00b0&col01#6&5b05f29&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}".

And I'm trying to open it using code, like:

//  First, open it with minimum permissions, this device may not be ours.
//  we'll re-open it later in read/write
hid_device_ref = CreateFile(
    device_path, GENERIC_READ,
    0, NULL, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, NULL);

I've considered a tool like FileMon or Process Monitor from SysInternals. But I can't seem to get it to report usage on device file handles like the one listed above.

解决方案

Have you tried the tool called handle from sysinternals?

Anyway, neither windows does this (display the name of the application that locked the device): when you try to eject an USB device, Windows just says that the device is currently in use and cannot be remove right now.

这篇关于找出哪个进程在USB设备句柄上具有排他锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆