14

I am working on a simple device driver I want to comunicate with the driver from user-mode using IRP.

I am having trouble opening the device driver. Using DeviceTree I am able to see the device name eg \Device\MyDevice.

But when I try to open it like this :

hand := CreateFile('\Device\MyDevice', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);  

I always get INVALID_HANDLE_VALUE and GetLastError is (The System cannot find the path specified)

What I am doing wrong ? I know the driver works because I can see it running and printing stuff in DebugView. So any tips ?

enter image description here

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
opc0de
  • 11,557
  • 14
  • 94
  • 187

1 Answers1

18

Here is a good explanation by Tim Robinson, MVP (Windows SDK):

Names of the form \Device\xxx are internal NT object manager names which are inaccessible to Win32. You will only be able to access your device if it creates a symbolic link to \Device\MyDevice from the \??\ directory. Objects in the \??\ kernel directory show up through \\.\ in Win32. Use Winobj in the DDK (or download it from www.sysinternals.com) to check.

NOTE: Nowadays NT namespace root is exposed via GLOBALROOT symbolic link, so any NT path is accessible to Win32 including \Device\xxx: use \\.\GLOBALROOT\Device\xxx. A device symlink is not required in such case.

Sergey Podobry
  • 7,101
  • 1
  • 41
  • 51
  • 3
    *You will only be able to access your device if it creates a symbolic link to \Device\MyDevice from the \??\ directory* - this is wrong. any symbolic link not need. and any NT path is **accessible** to win32, because exit `GLOBALROOT` symbolic link in *\GLOBAL??* to root of namespace. so we can access any path from win32 `CreateFileW` if append path with `"\\\\?\\Global\\GLOBALROOT"` or `"\\\\?\\GLOBALROOT"` (both is worked) so if we want access "\\Device\\xxx" - we can do this via "\\\\?\\GLOBALROOT\\Device\\xxx" name – RbMm Oct 11 '19 at 19:52
  • @RbMm Nice and very important addition! Thanks! – Sergey Podobry Oct 16 '19 at 15:21