0

Is there a good way to check for the existence of a device outside of the current driver stack in a KMDF framework? Perhaps via something like the physical device object name. I want to know if \Device\MyDeviceXXXexists from an unrelated driver. Also the device is a software-only device, no hardware involved.

James Parsons
  • 6,097
  • 12
  • 68
  • 108

1 Answers1

0

Depends on which IRQL you're running on. On PASSIVE_LEVEL you can try open the file, like:

UNICODE_STRING usname;
IO_STATUS_BLOCK iostatus;
OBJECT_ATTRIBUTES oa;
HANDLE hfile=NULL;

RtlInitUnicodeString(&usname, L"\\Device\\NDMP2"); // specify your device name here!!!
InitializeObjectAttributes(&oa, &usname, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
NTSTATUS status = ZwOpenFile(&hfile, GENERIC_READ, &oa, &iostatus, 0, 0);
if (status == 0 && hfile)
{
    // opened OK - device exists
    ZwClose(hfile);
}
else
{
    // no such device and/or error 
}
Kola73
  • 134
  • 1
  • 7