Nasıl yapılır: Yazıcı Kopyalama
Birçok işletme, bazı bir noktada aynı modelin birden çok yazıcıyı satın alır. Genellikle, bunların tümü, neredeyse özdeş yapılandırma ayarları ile yüklenir. Her yazıcının yüklenmesi zaman alabilir ve hataya yol açabilir. System.Printing.IndexedPropertiesInstallPrintQueue Microsoft .NET Framework ile sunulan ad alanı ve sınıf, var olan bir yazdırma sırasından kopyalanmış olan herhangi bir sayıda ek yazdırma sırasını anında yüklemeyi mümkün kılar.
Örnek
Aşağıdaki örnekte, ikinci bir yazdırma kuyruğu var olan bir yazdırma sırasından klonlanır. İkincisinin adı, konumu, bağlantı noktası ve paylaşılan durumunda ilki birinciden farklıdır. Bunu yapmanın önemli adımları aşağıdaki gibidir.
PrintQueueKopyalanacak var olan yazıcı için bir nesne oluşturun.
Öğesinden bir oluşturun PrintPropertyDictionaryPropertiesCollectionPrintQueue . ValueBu sözlükteki her girdinin özelliği, öğesinden türetilen türlerden birinin bir nesnesidir PrintProperty . Bu sözlükte bir girdinin değerini ayarlamak için iki yol vardır.
Girişi kaldırmak için sözlüğün kaldırma ve yöntemlerini kullanın ve ardından istenen değerle yeniden ekleyin.
Sözlüğün SetProperty metodunu kullanın.
Aşağıdaki örnekte her iki yol da gösterilmektedir.
Bir PrintBooleanProperty nesne oluşturun ve Name "IsShared" ve ' a ' olarak Value ayarlayın
true.Nesnesini, PrintBooleanPropertyPrintPropertyDictionary "IsShared" girişinin değeri olacak şekilde kullanın.
Bir PrintStringProperty nesne oluşturun ve bunu Name "ShareName" olarak ve Value uygun şekilde ayarlayın String .
PrintStringPropertyNesnesini PrintPropertyDictionary "ShareName" girişinin değeri olacak şekilde kullanın.
Başka bir PrintStringProperty nesne oluşturun ve bunu Name "konum" ve Value uygun olarak ayarlayın String .
İkinci PrintStringProperty nesneyi PrintPropertyDictionary "location" girişinin değeri olacak şekilde kullanın.
Bir dizisi oluşturun String . Her öğe, sunucudaki bir bağlantı noktasının adıdır.
Yeni bir InstallPrintQueue yazıcıyı yeni değerlerle birlikte yüklemek için kullanın.
Aşağıda bir örnek verilmiştir.
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()