您的位置:首页 > 汽车 > 新车 > Windows 获取打印机及端口号方法 (C#)

Windows 获取打印机及端口号方法 (C#)

2024/7/6 14:56:45 来源:https://blog.csdn.net/loveric/article/details/139974592  浏览:    关键词:Windows 获取打印机及端口号方法 (C#)

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.");}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com