다음을 통해 공유


방법: 프린터 복제

대부분의 기업에서는 같은 모델의 프린터를 여러 대 구입할 것입니다. 일반적으로 이러한 프린터는 모두 실제로 동일한 구성 설정을 사용하여 설치됩니다. 각 프린터를 설치하는 작업은 시간이 많이 걸리며 오류가 발생할 가능성도 큽니다. Microsoft .NET Framework으로 노출되는 System.Printing.IndexedProperties 네임스페이스와 InstallPrintQueue 클래스는 기존 인쇄 큐에서 복제되는 추가 인쇄 큐를 얼마든지 즉시 설치할 수 있게 해줍니다.

예제

아래의 예제에서 두 번째 인쇄 큐는 기존 인쇄 큐에서 복제됩니다. 두 번째 큐는 첫 번째와 이름, 위치, 포트 및 공유 상태만 다릅니다. 이 작업 수행의 주요 단계는 다음과 같습니다.

  1. 복제될 기본 프린터에 대해 PrintQueue 개체를 만듭니다.

  2. PrintQueuePropertiesCollection에서 PrintPropertyDictionary를 만듭니다. 이 사전에 있는 각 항목의 Value 속성은 PrintProperty에서 파생된 형식 중 하나의 개체입니다. 이 사전에 있는 항목의 값을 설정하는 방법은 두 가지입니다.

    • 사전의 RemoveAdd 메서드를 사용하여 항목을 제거한 다음 원하는 값을 사용하여 해당 항목을 다시 추가합니다.

    • 사전의 SetProperty 메서드를 사용합니다.

    다음 예제에서는 두 가지 방법을 보여 줍니다.

  3. PrintBooleanProperty 개체를 만들고 개체의 Name을 "IsShared"로 설정하고 개체의 Value를 true로 설정합니다.

  4. PrintPropertyDictionary의 "IsShared" 항목 값이 될 PrintBooleanProperty 개체를 사용합니다.

  5. PrintStringProperty 개체를 만들고 개체의 Name을 "ShareName"으로 설정하고 개체의 Value를 적절한 String으로 설정합니다.

  6. PrintPropertyDictionary의 "ShareName" 항목 값이 될 PrintStringProperty 개체를 사용합니다.

  7. 다른 PrintStringProperty 개체를 만들고 개체의 Name을 "Location"으로 설정하고 개체의 Value를 적절한 String으로 설정합니다.

  8. PrintPropertyDictionary의 "Location" 항목 값이 될 두 번째 PrintStringProperty 개체를 사용합니다.

  9. String의 배열을 만듭니다. 각 항목은 서버에 있는 포트의 이름입니다.

  10. InstallPrintQueue를 사용하여 새 값으로 새 프린터를 설치합니다.

예제는 아래와 같습니다.

                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();

참고 항목

참조

System.Printing.IndexedProperties

PrintPropertyDictionary

LocalPrintServer

PrintQueue

DictionaryEntry

개념

WPF의 문서

인쇄 개요