1. 打开注册表编辑器
regedit
2.选择如下配置
计算机\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Device
其中 “Ne01:” 为端口号
3. 代码 C#
using System;
using Microsoft.Win32;class Program
{static void Main(){string registryPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Devices";RegistryKey devicesKey = Registry.CurrentUser.OpenSubKey(registryPath);if (devicesKey != null){foreach (string printerName in devicesKey.GetValueNames()){string portName = devicesKey.GetValue(printerName).ToString();Console.WriteLine($"Printer: {printerName} on Port: {portName}");}}else{Console.WriteLine("No printers found in the registry.");}}
}