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.
En la mayoría de las empresas, en algún punto se adquieren varias impresoras del mismo modelo. Normalmente, todas ellas se instalan configuraciones casi idénticas. Instalar cada impresora puede exigir mucho tiempo y dar lugar a errores. El espacio de nombres System.Printing.IndexedProperties y la clase InstallPrintQueue que se exponen con Microsoft .NET Framework permiten instalar al instante cualquier número de colas de impresión adicionales que se clonan a partir de una existente.
Ejemplo
En el ejemplo siguiente, se clona una segunda cola de impresión a partir de otra existente. La segunda se diferencia de la primera únicamente en su nombre, ubicación, puerto y estado compartido. Los pasos principales para hacerlo son los siguientes.
Cree un objeto PrintQueue para la impresora existente que va a clonar.
Cree un objeto PrintPropertyDictionary a partir de la propiedad PropertiesCollection del objeto PrintQueue. La propiedad Value 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.
Utilizar los métodos Remove y Add del diccionario para quitar la entrada y, a continuación, volver a agregarla con el valor deseado.
Utilizar el método SetProperty del diccionario.
En el ejemplo siguiente se muestran ambas maneras.
Cree un objeto PrintBooleanProperty y establezca su propiedad Name en "IsShared" y su propiedad Value en true.
Utilice el objeto PrintBooleanProperty como valor de la entrada "IsShared" del objeto PrintPropertyDictionary.
Cree un objeto PrintStringProperty y establezca su propiedad Name en "ShareName" y su propiedad Value en un valor de tipo String apropiado.
Utilice el objeto PrintStringProperty como valor de la entrada "ShareName" del objeto PrintPropertyDictionary.
Cree otro objeto PrintStringProperty y establezca su propiedad Name en "Location" y su propiedad Value en un valor de tipo String apropiado.
Utilice el segundo objeto PrintStringProperty como valor de la entrada "Location" del objeto PrintPropertyDictionary.
Cree una matriz de objetos String. Cada elemento es el nombre de un puerto del servidor.
Utilice InstallPrintQueue para instalar la nueva impresora con los nuevos valores.
A continuación se muestra un ejemplo.
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()
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();
Vea también
Referencia
System.Printing.IndexedProperties