Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-clone-a-printer.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

4.3 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Clone a Printer 03/30/2017
csharp
vb
print queues [WPF]
cloning printers [WPF]
printers [WPF], cloning
print queues [WPF], cloning
cloning print queues [WPF]
dd6997c9-fe04-40f8-88a6-92e3ac0889eb

How to: Clone a Printer

Most businesses will, at some point, buy multiple printers of the same model. Typically, these are all installed with virtually identical configuration settings. Installing each printer can be time-consuming and error prone. The xref:System.Printing.IndexedProperties?displayProperty=nameWithType namespace and the xref:System.Printing.PrintServer.InstallPrintQueue%2A class that are exposed with Microsoft .NET Framework makes it possible to instantly install any number of additional print queues that are cloned from an existing print queue.

Example

In the example below, a second print queue is cloned from an existing print queue. The second differs from the first only in its name, location, port, and shared status. The major steps for doing this are as follows.

  1. Create a xref:System.Printing.PrintQueue object for the existing printer that is going to be cloned.

  2. Create a xref:System.Printing.IndexedProperties.PrintPropertyDictionary from the xref:System.Printing.PrintSystemObject.PropertiesCollection%2A of the xref:System.Printing.PrintQueue. The xref:System.Collections.DictionaryEntry.Value%2A property of each entry in this dictionary is an object of one of the types derived from xref:System.Printing.IndexedProperties.PrintProperty. There are two ways to set the value of an entry in this dictionary.

    The example below illustrates both ways.

  3. Create a xref:System.Printing.IndexedProperties.PrintBooleanProperty object and set its xref:System.Printing.IndexedProperties.PrintProperty.Name%2A to "IsShared" and its xref:System.Printing.IndexedProperties.PrintBooleanProperty.Value%2A to true.

  4. Use the xref:System.Printing.IndexedProperties.PrintBooleanProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "IsShared" entry.

  5. Create a xref:System.Printing.IndexedProperties.PrintStringProperty object and set its xref:System.Printing.IndexedProperties.PrintProperty.Name%2A to "ShareName" and its xref:System.Printing.IndexedProperties.PrintStringProperty.Value%2A to an appropriate xref:System.String.

  6. Use the xref:System.Printing.IndexedProperties.PrintStringProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "ShareName" entry.

  7. Create another xref:System.Printing.IndexedProperties.PrintStringProperty object and set its xref:System.Printing.IndexedProperties.PrintProperty.Name%2A to "Location" and its xref:System.Printing.IndexedProperties.PrintStringProperty.Value%2A to an appropriate xref:System.String.

  8. Use the second xref:System.Printing.IndexedProperties.PrintStringProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "Location" entry.

  9. Create an array of xref:System.Strings. Each item is the name of a port on the server.

  10. Use xref:System.Printing.PrintServer.InstallPrintQueue%2A to install the new printer with the new values.

An example is below.

[!code-csharpClonePrinter#ClonePrinter] [!code-vbClonePrinter#ClonePrinter]

See also