Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
La mayoría de las empresas comprarán, en algún momento, varias impresoras del mismo modelo. Normalmente, todos se instalan con valores de configuración prácticamente idénticos. La instalación de cada impresora puede llevar mucho tiempo y ser propensa a errores. El System.Printing.IndexedProperties espacio de nombres y la InstallPrintQueue clase que se exponen con Microsoft .NET Framework permite instalar instantáneamente cualquier número de colas de impresión adicionales que se clonan desde una cola de impresión existente.
Ejemplo
En el ejemplo siguiente, se clona una segunda cola de impresión a partir de una cola de impresión existente. El segundo difiere del primero solo en su nombre, ubicación, puerto y estado compartido. Los pasos principales para hacerlo son los siguientes.
Cree un PrintQueue objeto para la impresora existente que se va a clonar.
Cree un PrintPropertyDictionary a partir del PropertiesCollection del PrintQueue. La Value propiedad de cada entrada de este diccionario es un objeto de uno de los tipos derivados de PrintProperty. Hay dos maneras de establecer el valor de una entrada en este diccionario.
Use los métodos Remove y Add del diccionario para quitar la entrada y, a continuación, volver a agregarla con el valor deseado.
Utilice el método SetProperty del diccionario.
En el ejemplo siguiente se muestran ambas maneras.
Cree un objeto PrintBooleanProperty y establezca su Name en "IsShared" y su Value en
true
.Usa el objeto PrintBooleanProperty como valor de la entrada 'IsShared' de PrintPropertyDictionary.
Cree un PrintStringProperty objeto y establezca su Name en "ShareName" y su Value en un String apropiado.
Usa el objeto PrintStringProperty como valor de la entrada "ShareName" de PrintPropertyDictionary.
Cree otro PrintStringProperty objeto y establezca su Name a "Location" y su Value a un adecuado String.
Use el segundo PrintStringProperty objeto para ser el valor de la PrintPropertyDictionaryentrada "Ubicación".
Cree una matriz de Strings. Cada elemento es el nombre de un puerto en el servidor.
Use InstallPrintQueue para instalar la nueva impresora con los nuevos valores.
A continuación se muestra un ejemplo.
LocalPrintServer myLocalPrintServer = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties = sourcePrintQueue.PropertiesCollection;
// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared", true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);
// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +"\"");
myPrintProperties.SetProperty("ShareName", theShareName);
// Specify the physical ___location of the new printer using Remove/Add methods
PrintStringProperty theLocation = new PrintStringProperty("Location", "the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);
// Specify the port for the new printer
String[] port = new String[] { "COM1:" };
// Install the new printer on the local print server
PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue("My clone of " + sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties);
myLocalPrintServer.Commit();
// Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName);
Console.WriteLine("Press Return to continue ...");
Console.ReadLine();
Dim myLocalPrintServer As New LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer)
Dim sourcePrintQueue As PrintQueue = myLocalPrintServer.DefaultPrintQueue
Dim myPrintProperties As PrintPropertyDictionary = sourcePrintQueue.PropertiesCollection
' Share the new printer using Remove/Add methods
Dim [shared] As New PrintBooleanProperty("IsShared", True)
myPrintProperties.Remove("IsShared")
myPrintProperties.Add("IsShared", [shared])
' Give the new printer its share name using SetProperty method
Dim theShareName As New PrintStringProperty("ShareName", """Son of " & sourcePrintQueue.Name & """")
myPrintProperties.SetProperty("ShareName", theShareName)
' Specify the physical ___location of the new printer using Remove/Add methods
Dim theLocation As New PrintStringProperty("Location", "the supply room")
myPrintProperties.Remove("Location")
myPrintProperties.Add("Location", theLocation)
' Specify the port for the new printer
Dim port() As String = { "COM1:" }
' Install the new printer on the local print server
Dim clonedPrinter As PrintQueue = myLocalPrintServer.InstallPrintQueue("My clone of " & sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties)
myLocalPrintServer.Commit()
' Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName)
Console.WriteLine("Press Return to continue ...")
Console.ReadLine()
Consulte también
.NET Desktop feedback