如何使用 C# 更改打印机的端口名称

发布于 2024-12-01 23:39:23 字数 302 浏览 2 评论 0原文

我已经扫描了,但没有看到这个问题,如果我错过了,很抱歉,这是重复的。

我可以在 PrinterSettings.InstalledPrinters 中找到网络打印机,并从 Printer.Properties 中获取“PortName”属性,但仅设置该属性不起作用。我试图在注册表中暴力更改该打印机端口名,但这也不起作用(尽管我真的不认为它会起作用,但不得不尝试)。

我通过 reg 文件加载实现了新端口,因此不需要构建端口。 (顺便说一句,我知道该端口可以正常工作,因为在打印机属性中设置它效果很好)。

感谢您的帮助。

谢谢

I've scanned SO and didn't see this question posted, sorry if I missed it and this is a repeat.

I can locate the network printer in the PrinterSettings.InstalledPrinters, and fetch the "PortName" property from printer.Properties, but just setting the property doesn't work. I tried to brute force the change for that printer portname in the registry and that didn't work either (although I really didn't think it would but had to try).

I have the new port implemented through a reg file load so don't need to build a port. (BTW I know the port works because setting it in the printer properties works fine).

Your help appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-12-08 23:39:23

您可以使用 WMI 设置打印机的端口名称。
这是一个例子:

ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();

// Insert your printer name in the WHERE clause...
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE Name='PrinterName");


foreach (ManagementObject printer in searcher.Get())
{
  printer["PortName"]="LPT1:";
  printer.Put();  // Important: Call put to save the settings.
}

希望,这有帮助。

You could use WMI to set the PortName for your printer.
Here is an example:

ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();

// Insert your printer name in the WHERE clause...
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer WHERE Name='PrinterName");


foreach (ManagementObject printer in searcher.Get())
{
  printer["PortName"]="LPT1:";
  printer.Put();  // Important: Call put to save the settings.
}

Hope, this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文