This article explains how to Query logical DOS names for their NT naming convention using QueryDosDevice. It explains how to add and remove Logical Device names using their NT naming convention using DefineDosDevice. The article explains that a DOS name is required to access various devices.
“Win32 programs cannot use internal
Windows NT device names to access
devices because the Win32 subsystem
and Win32 API require the more
familiar drive letters and MS-DOS
device names, such as A:, C:, COM1:,
and LPT1”
I found this interesting article that gets all the available DOS Names and then queries for the NT Name using the function GetLogicalDriveString. This article does not explain how to return all defined DOS names for devices, just drives.
However, I would like to know how to do the reverse. How would I get a list of NT device names. I am not looking for just drives but all devices. For example LPT1 and COM1 are reserved DOS names that correspond to specific NT names. I would like to map additional devices they may not have a DOS name so that I can use the WINAPI function CreateFile.
How do I get a list of all NT device names oppose to DOS Names?
Well underneath the hood the DosDevice’s are symbolic links in the NT Object Manager database pointing to the underlying devices. I would recommend playing with WinObj to get a feel for how things are put together.
Unfortunately to do the enumeration yourself and to add your own custom symbolic links you would need to use the native NT apis (see this for abit on enumerating stuff). You can sometimes play some tricks with the DefineDosDevice function to do some mappings, however you don’t actually need to do that if you just want to access objects through CreateFile. You can use the NT native escape syntax to access anything in the NT Object Manager database, just prefix your native path with
\\?\GLOBALROOTand pass that to the CreateFile, e.g. if you want to access the floppy drive useCreateFile(L"\\?\GLOBALROOT\Device\Floppy0", ...);