列出 Win32 设备命名空间的内容

List the content of the Win32 device namespace

来自微软独库:

The "\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace. This is how access to physical disks and volumes is accomplished directly, without going through the file system, if the API supports this type of access. You can access many devices other than disks this way (using the CreateFile and DefineDosDevice functions, for example).

For example, if you want to open the system's serial communications port 1, you can use "COM1" in the call to the CreateFile function. This works because COM1–COM9 are part of the reserved names in the NT namespace, although using the "\.\" prefix will also work with these device names.

我的问题是,这个命名空间中有什么可用。是否有设备列表,我在哪里可以得到它? (我想我没听懂这个话题。当我听到设备时,我想到了目录中的某种文件。)

编辑:

好的,我会回答我自己的问题。有一个叫WinObj的软件,用它可以看到信息。

好的,我会回答我自己的问题。有一个叫WinObj的软件,用它可以看到信息。

您可以使用 QueryDosDevice Win32 API 调用来获取所有 Win32 设备名称。

#include <windows.h>
#include <stdio.h>

#define DEVBUFSIZ (128 * 1024)      /* No recommended value - ~14K for me */
int main(int argc, char** argv)
{
    wchar_t devicenames[DEVBUFSIZ]  = L"";
    int     error                   = 0;
    int     wchar_count             = 0;

    wchar_count = QueryDosDeviceW(
            NULL,       /* lpDeviceName - NULL gives all */
            devicenames,
            DEVBUFSIZ);
    if (wchar_count == 0) {
        fprintf(stderr, "QueryDosDeviceW failed with error code %d\n", error);
        return 1;
    }
    for (int i = 0; i < wchar_count; i++) {
        if (devicenames[i] == '[=10=]')
            devicenames[i] = '\n';
    }
    wprintf(L"%s", devicenames);
    return 0;
}

顺便说一句,WinObj 主要不列出 Win32 设备名称,它列出 Windows NT 对象名称。尽管可以在 WinObj 的 GLOBAL?? 节点下找到 Win32 设备名称。

参见 https://support.microsoft.com/en-us/kb/100027

中的 "More Information"