CreateFile with ERROR_ACCESS_DENIED in SPBTestTool of WDK sample code RRS feed

  • Question

  • Hi,

    Recently, I use spbtesttool.exe (source code be modied as below) in command Prompt windows  to access spbtesttool.sys (one of I2C device) that hw ID following  bios ASL setting in windows 10(ver.10.10.14393).  After several rebooting in this nb with LAN on, I use spbtesttool.exe  in command Prompt windows  to access spbtesttool.sys, and the function is abnormal. After debugging spbtesttool.exe & spbtesttool.sys.

    App side:

    I found CreateFileA retrun INVALID_HANDLE_VALUE and system error is ERROR_ACCESS_DENIED.  some part of source code  as below. What can I do then I can use CreateFileA to get its handle?


    g_Peripheral = CreateFileA(  SPBTESTTOOL_USERMODE_PATH,
     if ((NULL == g_Peripheral) || (INVALID_HANDLE_VALUE ==g_Peripheral )) {
      printf("CreateFileA %s fail, errorcode =%ld\n", SPBTESTTOOL_USERMODE_PATH, GetLastError());
      return false;

     if ((DeviceIoControl(
      &Overlapped) == TRUE) ||
      (GetLastError() != ERROR_IO_PENDING))
      FakeCompletion(GetLastError(), bytesReturned);
      return false;

    Drvier side:

        1.In this condition , this device driver is functional well from observing device management .

        2.I use SC.exe query type=driver, and the driver (spbtesttool.sys) is running.

       3. Adding write log to file in spbtesttool.sys, DriverEntry/ODeviceAdd be executed normally during reboot period , it log shows "Created WDF driver object" and ODeviceAdd function finish all initialization/configuration/registry checking.

        4. During executing app that createfile show R_ACCESS_DENIED  , there is no log string in driver code no matter by write file or Debugview.

    Anderson MSDN alern with virtual camera

    Monday, December 18, 2017 12:02 PM

All replies

  • The security check is most likely happening in the io manager (and failing there) before the create request is sent to the devic object. By default you must be an admin to open handle to a device driver. Are you running the command prompt elevated? Logging in as admin is insufficient.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, December 18, 2017 3:41 PM
  • Hi, Doron,

    I met "CreateFileA retrun INVALID_HANDLE_VALUE and system error is ERROR_ACCESS_DENIED" under below condition. Is there any setting I missing so that I can't get device handle?

    1. I used  adiministrator: command Prompt windows  to execute my app, and this app(c++) built from VS2017-> property setting->linker-> ...->UAC -> requirAdministrator (/level='requirAdministrator')

    2.The driver(spbtesttool.sys) is un-signed driver , but I install it in test mode. (I used bcdedit.exe /set testsigning on & reboot press F7 to "Disable driver signature enforcement").

    Anderson MSDN alern with virtual camera

    • Edited by anderson0n Tuesday, December 19, 2017 6:04 AM
    Tuesday, December 19, 2017 4:14 AM
  • I can duplicate the abnormal condition after first windows update and reboot.

    The update item is KB4054517.

    After removing from windows update, this item will be update and installed in the next rebooting to S0/

    I don't know its relative with windows defender policy or what changed policy.This changing let executed app can't touch device (CreateFile , and last error tell ERROR_ACCESS_DENIED).

    • Edited by anderson0n Friday, December 22, 2017 1:46 AM
    Thursday, December 21, 2017 9:34 AM
  • Did you root caused the issue?

    Do you know why this update blocks apps from devices?

    This sounds very weird, like MSFT introduced new setting that we are not aware of..

    Tuesday, March 20, 2018 1:33 PM