简体   繁体   English

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

[英]List the content of the Win32 device namespace

From the microsoft-doku: 从microsoft-doku:

The "\\\\.\\" prefix will access the Win32 device namespace instead of the Win32 file namespace. "\\\\.\\"前缀将访问Win32设备名称空间,而不是Win32文件名称空间。 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. 如果API支持这种类型的访问,则可以通过此方法直接完成对物理磁盘和卷的访问,而无需通过文件系统。 You can access many devices other than disks this way (using the CreateFile and DefineDosDevice functions, for example). 您可以通过这种方式访问​​磁盘以外的许多设备(例如,使用CreateFile和DefineDosDevice函数)。

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. 例如,如果要打开系统的串行通信端口1,则可以在对CreateFile函数的调用中使用“ COM1”。 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. 这是可行的,因为COM1-COM9是NT名称空间中保留名称的一部分,尽管使用"\\\\.\\"前缀也可以与这些设备名称一起使用。

My Question is, what is available in this namespace. 我的问题是,此命名空间中有什么可用。 Is there a list of devices and where can I get it ? 是否有设备列表,我在哪里可以得到? (I think I did not understand this topic. When I hear device I think of some sort of file in a directory.) (我认为我听不懂这个主题。听到设备时,我会想到目录中的某种文件。)

EDIT: 编辑:

Ok, I will answer my own question. 好吧,我会回答我自己的问题。 There is a software called WinObj , with which one can see the information . 有一个名为WinObj的软件,可以用它查看信息。

Ok, I will answer my own question. 好吧,我会回答我自己的问题。 There is a software called WinObj , with which one can see the information . 有一个名为WinObj的软件,可以用它查看信息。

You can use the QueryDosDevice Win32 API call to get all Win32 device names. 您可以使用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] == '\0')
            devicenames[i] = '\n';
    }
    wprintf(L"%s", devicenames);
    return 0;
}

As an aside, WinObj does not primarily list Win32 device names, it lists Windows NT object names. 顺便说一句,WinObj并不主要列出Win32设备名称,而是列出Windows NT对象名称。 Though the Win32 device names can be found under the GLOBAL?? 尽管可以在GLOBAL??下找到Win32设备名称GLOBAL?? node in WinObj. WinObj中的节点。

See "More Information" in https://support.microsoft.com/en-us/kb/100027 请参阅https://support.microsoft.com/zh-cn/kb/100027中的 “更多信息”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM