Win32-Api C++ 中的 CreateFile(...) 失败

Win32-Api CreateFile(...) in C++ failed

以下代码在一台 PC 下运行,但在另一台 PC 上运行不正常。两台 PC 的 Windows 7 作为他们的 OS.

char device_name[] = "\\.\interception00";
printf("device_name: %s \n", device_name);

device_array[i].handle = CreateFile(device_name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

DWORD error = GetLastError();
printf("GetLastError (Number): %d, ", error);

if (error == ERROR_FILE_NOT_FOUND)
{
    printf("error == ERROR_FILE_NOT_FOUND \n");
}
else if (error == ERROR_SUCCESS)
{
    printf("error == ERROR_SUCCESS \n");
}
else
{
    printf("error == UNBEKANNT \n");
}

成功打开文件的PC输出:

device_name: \.\interception00
GetLastError (Number): 0, error == ERROR_SUCCESS

另一台电脑无法打开文件。输出是:

device_name: \.\interception00
GetLastError (Number): 2, error == ERROR_FILE_NOT_FOUND 

有人知道为什么会这样吗?可能是权限不够的问题?

来自 MSDN 的 CreateFile() documentation

OPEN_EXISTING

Opens a file or device, only if it exists.

If the specified file or device does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).

所以这意味着 \\.\interception00 存在于一台计算机上,但不存在于另一台计算机上。尝试查看其他通常能够打开 File/Device.

的程序

或者只是修复 \\.\interception00 不可用。