* 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
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 |
|
|
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.
-
Create a xref:System.Printing.PrintQueue object for the existing printer that is going to be cloned.
-
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.
-
Use the dictionary's Remove and xref:System.Printing.IndexedProperties.PrintPropertyDictionary.Add%2A methods to remove the entry and then re-add it with the desired value.
-
Use the dictionary's xref:System.Printing.IndexedProperties.PrintPropertyDictionary.SetProperty%2A method.
The example below illustrates both ways.
-
-
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. -
Use the xref:System.Printing.IndexedProperties.PrintBooleanProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "IsShared" entry.
-
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.
-
Use the xref:System.Printing.IndexedProperties.PrintStringProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "ShareName" entry.
-
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.
-
Use the second xref:System.Printing.IndexedProperties.PrintStringProperty object to be the value of the xref:System.Printing.IndexedProperties.PrintPropertyDictionary's "Location" entry.
-
Create an array of xref:System.Strings. Each item is the name of a port on the server.
-
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]