4

I am creating a UMDF driver which needs to change the brightness of the LCD back light.

The following line of code works in a Console App and successfully returns a handle to the device:

HANDLE hDevice = CreateFile(L"\\\\.\\LCD", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);

However, when I use the exact same piece of code in my driver it returns INVALID_HANDLE_VALUE and GetLastError() gives code 5 which is 'Access is denied'

The driver is being debugged remotely on an x64 Windows 7 machine using the standard WDKRemoteUser profile.

Does anyone know what the problem might be? Do I need to set permissions and, if so, how?

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
Simon
  • 41
  • 1
  • 2
  • `CreateFile` is part of the Win32 API, how are you using that from a driver? Or are you really calling `ZwCreateFile`? – Benj Oct 24 '12 at 15:47
  • Hi BenJ! Is it just a case of me using an incorrect function then? I will give the ZwCreateFile a try :) Will I still be able to use DeviceIoControl() if I manage to obtain the handle, or is there a special driver function for that as well that I need to use? – Simon Oct 25 '12 at 09:21
  • 1
    Apologies, I haven't used UMDF, it looks as though using the Win32 API is completely fine in that environment. – Benj Oct 25 '12 at 09:42

1 Answers1

2

It sounds as though you need to impersonate the drivers client.

UMDF drivers typically run under the LocalService account and cannot access files or resources that require user credentials, such as protected files or other protected resources. A UMDF driver typically operates on commands and data that flow between a client application and a device. Therefore, most UMDF drivers do not access protected resources.

The framework provides an impersonation capability that allows drivers to impersonate the driver's client and obtain the client's access rights to protected resources.

Benj
  • 31,668
  • 17
  • 78
  • 127