Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Większość firm kupi w pewnym momencie wiele drukarek tego samego modelu. Zazwyczaj są one instalowane z praktycznie identycznymi ustawieniami konfiguracji. Instalowanie każdej drukarki może być czasochłonne i podatne na błędy. Przestrzeń nazw System.Printing.IndexedProperties i klasa InstallPrintQueue uwidoczniona w programie Microsoft .NET Framework umożliwia natychmiastowe zainstalowanie dowolnej liczby dodatkowych kolejek wydruku sklonowanych z istniejącej kolejki wydruku.
Przykład
W poniższym przykładzie druga kolejka drukowania jest tworzona jako kopia istniejącej kolejki drukowania. Drugi różni się od pierwszego tylko w nazwie, lokalizacji, porcie i statusie udostępnienia. Główne kroki w tym celu są następujące.
Utwórz obiekt PrintQueue dla istniejącej drukarki, która ma zostać sklonowana.
Utwórz PrintPropertyDictionary na podstawie PropertiesCollection z PrintQueue. Właściwość Value każdego wpisu w tym słowniku jest obiektem jednego z typów pochodzących z PrintProperty. Istnieją dwa sposoby ustawiania wartości wpisu w tym słowniku.
Użyj metody Remove i Add słownika, aby usunąć wpis, a następnie ponownie dodać go z żądaną wartością.
Użyj metody słownika SetProperty.
W poniższym przykładzie przedstawiono oba sposoby.
Utwórz obiekt PrintBooleanProperty i ustaw jego Name na "IsShared" i jego Value na
true
.Użyj obiektu PrintBooleanProperty jako wartość we wpisie "IsShared" w PrintPropertyDictionary.
Utwórz obiekt PrintStringProperty i ustaw jego Name na wartość "ShareName" oraz przypisz jego Value do odpowiedniego String.
Użyj obiektu PrintStringProperty jako wartości dla pozycji „ShareName” w PrintPropertyDictionary.
Utwórz inny obiekt PrintStringProperty i ustaw jego Name na "Lokalizacja" i jego Value na odpowiedni String.
Użyj drugiego obiektu PrintStringProperty, aby być wartością wpisu PrintPropertyDictionary"Lokalizacja".
Utwórz tablicę Strings. Każdy element jest nazwą portu na serwerze.
Użyj InstallPrintQueue, aby zainstalować nową drukarkę z nowymi wartościami.
Poniżej przedstawiono przykład.
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()
Zobacz także
.NET Desktop feedback