1. 打開注冊表編輯器
regedit
2.選擇如下配置
計算機\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Device
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.");}}
}