Windows PE 不为串行端口创建符号名称,如 COM1 和 COM2。这意味着应用程序无法
检测和使用这些串行端口。
解决方法:要为串行端口创建符号名称,可以编写一个调用 DefineDosDevice 函数
并使用该端口的完整设备名称的应用程序。然后将该应用程序添加到 Startnet.cmd
中,以便其作为 Windows PE 启动过程的一部分运行。该应用程序结束后,其他应用
程序就能够根据串行端口的符号名称检测到相应的串行端口。
在部署该应用程序之前,必须在脱机 Windows PE 映像中添加相应的注册表项,之后
才能使用串行端口。
This sample shows how to associate an MS-DOS device name with a
Windows NT device name. The association is a symbolic link between
device names stored in the Object Manager's namespace. Applications
use the MS-DOS device name, but Windows NT and kernel-mode drivers
use the Windows NT device name.
NOTE: If the MS-DOS device name is a driver letter, the trailing
backlash is not accepted by DefineDosDevice or QueryDosDevice.
NOTE: The MS-DOS device name is defined only until the computer is
restarted.
To make the drive letter associations permanent on Window NT 4.0, you
have to update HKEY_LOCAL_MACHINE\SYSTEM\DISK\Information. However,
the contents of the value are undocumented.
On Windows 2000, you have to use the Volume Mount Point APIs.
*/
#define WIN32_LEAN_AND_MEAN /* Reduce number of system headers parsed */
/* during build. */
/*
Command-line parsing.
1) Make sure correct number of arguments are supplied.
2) See if you should add or remove the MS-DOS Device Name.
*/
if (argc != 3)
{
printf("\nusage: %s <DOS device name> <NT device name> to add\n",
argv[0]);
printf("usage: %s [-r] <DOS device name> to remove\n",
argv[0]);
printf("\n\texample: %s d: \\device\\cdrom0\n", argv[0]);
return;
}
fRemoveDeviceName = !lstrcmpi (argv[1], "-r");
/* Now, add/remove the DOS device name. */
if (fRemoveDeviceName)
{
/*
Remove the MS-DOS device name. First, get the name of the Windows
NT device from the symbolic link, then delete the symbolic link.
fResult = DefineDosDevice (DDD_RAW_TARGET_PATH, pszDosDeviceName,
pszNtDeviceName);
if (!fResult)
printf("error %lu: could not link %s to %s\n",
GetLastError(), pszDosDeviceName, pszNtDeviceName);
}
下列代码演示如何创建符号链接 (ServerCOM1) 到终端服务器上首物理串行端口: // Map ServerCOM1 to the first physical serial port on the TS server.
// Before you create the new mapping, verify that it does not already exist.