如何使用 .NET 安装打印机? [英] How can I install a printer using .NET?

查看:87
本文介绍了如何使用 .NET 安装打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个虚拟打印机的 .INF,我需要从 .NET 应用程序安装它.我在使用批处理脚本之前已经这样做了,但我正在寻找一段代码来在 .NET Framework 中做到这一点.

I have an .INF for a virtual printer that I need to install from a .NET Application. I have done this before using batch scripts, but I am looking for a snippet of code to do this in the .NET Framework.

打印机 .INF 没有什么特别之处,因此任何从 C# 或 VB.NET 中的 INF 安装打印机的代码都可以工作.

There's nothing particular about the printer .INF, so any code that installs a printer from an INF in C# or VB.NET will work.

推荐答案

我相信这可以通过互操作到本机 win32 API 来实现,但我发现仅使用 System.Diagnostics.Process() 就容易多了通过以下方式调用printui.dll:

I believe this is possible via interop to native win32 APIs, but I've found its much, much easier just to use a System.Diagnostics.Process() to call into printui.dll via:

rundll32.exe printui.dll,PrintUIEntry/?

也许您已经在提到的批处理脚本中使用了它,但如果没有,则此处记录了参数:PrintUI.DLL 用户指南和参考

Perhaps you're already using that in the mentioned batch script, but if not the parameters are documented here: PrintUI.DLL User's Guide and Reference

请务必针对您需要支持的所有操作系统对其进行测试.某些选项要么在所有 Windows 版本中都不存在,要么已被重命名(尽管我认为它们是更深奥的选项 - 安装 .INF 可能会全面有效).

Just be sure to test it against all operation systems you need to support. Some options either do not exist in all Windows releases or have been renamed (although I think they're the more esoteric options - installing an .INF will likely work across the board).

这篇关于如何使用 .NET 安装打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆