CreateFile for \\.\usbscan0 returns ERROR_FILE_NOT_FOUND

39 views Asked by At

I'm trying to find usb device by vid/pid, scanning usb ports:

for (int i = 0; i < 127; i++) {
        char fileName[30] = "";
        wsprintf(fileName, "\\\\.\\usbscan%d", i);
        m_deviceHandle = ::CreateFile(  fileName, 
                                        GENERIC_READ | GENERIC_WRITE,
                                        FILE_SHARE_READ | FILE_SHARE_WRITE, 
                                        NULL, OPEN_EXISTING, 
                                        FILE_ATTRIBUTE_SYSTEM, NULL);
       ..................
}

But always get INVALID_HANDLE_VALUE with error code 2. I tried different file attributes - no affect. usbscan.sys presented in System32\Drivers. What can be a reason ?

0

There are 0 answers