Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
De flesta företag kommer någon gång att köpa flera skrivare av samma modell. Dessa installeras vanligtvis med praktiskt taget identiska konfigurationsinställningar. Att installera varje skrivare kan vara tidskrävande och felbenäget. Namnområdet System.Printing.IndexedProperties och InstallPrintQueue klassen som exponeras med Microsoft .NET Framework gör det möjligt att omedelbart installera ett antal ytterligare utskriftsköer som klonas från en befintlig utskriftskö.
Exempel
I exemplet nedan klonas en andra utskriftskö från en befintlig utskriftskö. Den andra skiljer sig från den första endast i dess namn, plats, port och delade status. De viktigaste stegen för att göra detta är följande.
Skapa ett PrintQueue objekt för den befintliga skrivaren som ska klonas.
Skapa en PrintPropertyDictionary från PropertiesCollection i PrintQueue. Egenskapen Value för varje post i den här ordlistan är ett objekt av en av de typer som härleds från PrintProperty. Det finns två sätt att ange värdet för en post i den här ordlistan.
Använd ordlistans Ta bort och Add metoder för att ta bort posten och sedan lägga till den igen med önskat värde.
Använd ordlistans SetProperty metod.
Exemplet nedan illustrerar båda sätten.
Skapa ett PrintBooleanProperty objekt och ange dess Name till "IsShared" och dess Value till
true.Använd objektet PrintBooleanProperty för att vara värdet för PrintPropertyDictionaryposten "IsShared".
Skapa ett PrintStringProperty objekt och ange dess Name till "ShareName" och dess Value till en lämplig String.
Använd objektet PrintStringProperty för att vara värdet för PrintPropertyDictionaryposten "ShareName".
Skapa ett annat PrintStringProperty objekt och ställ in det Name på "Plats" och dess Value till en lämplig String.
Använd det andra PrintStringProperty objektet för att vara värdet för PrintPropertyDictionaryposten "Plats".
Skapa en matris med Strings. Varje objekt är namnet på en port på servern.
Använd InstallPrintQueue för att installera den nya skrivaren med de nya värdena.
Ett exempel finns nedan.
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()
Se även
.NET Desktop feedback