简体   繁体   English

如何在Windows上的C ++中重命名打印机?

[英]How to rename a printer in C++ on Windows?

在WinSpool.h中,我可以使用EnumPrinters函数枚举所有打印机,但是找不到如何重命名现有打印机?

You can use the SetPrinter function to rename a printer. 您可以使用SetPrinter函数来重命名打印机。

You would set the Level parameter to 2 and the pPrinter parameter would point to a PRINTER_INFO_2 structure. 您可以将Level参数设置为2 ,而pPrinter参数将指向PRINTER_INFO_2结构。 The PRINTER_INFO_2::pPrinterName field lets you change the printer name. PRINTER_INFO_2::pPrinterName字段使您可以更改打印机名称。

Note that the docs for SetPrinter say: 请注意, SetPrinter的文档说:

To modify the current printer settings, call the GetPrinter function to retrieve the current settings into a PRINTER_INFO_2 structure, modify the members of that structure as necessary, and then call SetPrinter . 要修改当前打印机设置,请调用GetPrinter函数以将当前设置检索到PRINTER_INFO_2结构中,根据需要修改该结构的成员,然后调用SetPrinter

So you would need to call GetPrinter with a properly initialized structure first, before modifying the name and calling SetPrinter . 因此,您需要先使用正确初始化的结构调用GetPrinter ,然后再修改名称并调用SetPrinter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM