Search code examples
winapidevice-driver

Getting the Windows Drivers Directory


Is there an official / proper method of getting Windows’ drivers directory or do you just concatenate "\\Drivers" to GetSystemDirectory()?

To be clear, I mean the Drivers directory that is in the system directory (eg System32). Yes, drivers can technically be anywhere, but is there an official way (eg a function) to get this specific directory?


Solution

  • It's hard-coded into the kernel, although drivers don't have to be loaded from there. Here's some bits taken from various parts of the I/O subsystem, which loads drivers:

    #define SYSTEM32_DRIVERS_DIR        (L"\\System32\\drivers\\")
    
    ...
    
            pathLength = sizeof(L"\\SystemRoot\\System32\\Drivers\\") - sizeof(UNICODE_NULL);
            path = L"\\SystemRoot\\System32\\Drivers\\";
    ...