2016-04-14 3 views
0

を取得します。 C#を使用して、私は、システムにインストールされたプリンタのリストを持っているが、各プリンタのスプーラID /名称と接続タイプを決定する必要があります。私は自動的に印刷された文書に基づいてプリンタを切り替えるためにC#を使用したアプリケーションのための小さなプラグインを作成していプリンタースプーラ名&接続タイプ

基本的に私は、ホストアプリケーションは、次の印刷に使用するデフォルトのプリンタを処理するために使用し、値がプリンタ名の形式であるレジストリキーを変更しています。スプーラ、接続タイプは、異なるプリンタに固有のように見えます。ここで

は私が構築するために必要な値の一例である:HP LaserJet 5500,winspool,Ne01:

私はちょうど、各プリンタの他のparamsを取得する方法がわからプリンタ名を持っていません。

は、私はプリンタのリストを取得するために使用していたコードフラグメントは、System.Drawingに依存しています。

foreach (string printer in PrinterSettings.InstalledPrinters) 

    Console.WriteLine(printer); 

    var printerSettings = new PrinterSettings(); 
    Console.WriteLine(printerSettings.PrinterName); 
} 

答えて

1

私はこのことがあなたを助けてくれるのか、少なくとも最終結果のより深い道を歩いていくのか分かりません。私はプリンタのコンポーネント/ドライバの設定を調べ、これを持っている同様の必要性を持っていた。私は私のマシン上で、私が持っているプリンタごとにそれぞれの可能なタイプのスイッチ/ケースを持っているが、そこに他のものとすることができ、あなたは一時停止して、より深いネストの要素であるかもしれない設定のより掘り下げことができます。私が必要としていたものがqueue.DefaultPrintTicketで見つかり、ラベルプリンタのx/yページ解像度を調べました。

using System.Printing; 

     var ps = new PrintServer(); 
     var queues = ps.GetPrintQueues(
      new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }); 

     // The AMSConfig table has width of 70 for binding to match. 
     StringBuilder sb = new StringBuilder(); 
     foreach (var queue in queues) 
     { 
      sb.AppendLine(queue.Name); 
      if (queue.PropertiesCollection == null) 
       continue; 

      foreach (System.Collections.DictionaryEntry ppd in queue.PropertiesCollection) 
      { 
       switch(ppd.Value.ToString()) 
       { 
        case "System.Printing.IndexedProperties.PrintStringProperty": 
         var psp = ppd.Value as System.Printing.IndexedProperties.PrintStringProperty; 
         sb.AppendLine(ppd.Key + " : " + psp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintInt32Property": 
         var pip = ppd.Value as System.Printing.IndexedProperties.PrintInt32Property; 
         sb.AppendLine(ppd.Key + " : " + pip.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintTicketProperty": 
         var ptp = ppd.Value as System.Printing.IndexedProperties.PrintTicketProperty; 
         sb.AppendLine(ppd.Key + " : " + ptp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintBooleanProperty": 
         var pbp = ppd.Value as System.Printing.IndexedProperties.PrintBooleanProperty; 
         sb.AppendLine(ppd.Key + " : " + pbp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintQueueStatusProperty": 
         var pstap = ppd.Value as System.Printing.IndexedProperties.PrintQueueStatusProperty; 
         sb.AppendLine(ppd.Key + " : " + pstap.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintQueueAttributeProperty": 
         var pap = ppd.Value as System.Printing.IndexedProperties.PrintQueueAttributeProperty; 
         sb.AppendLine(ppd.Key + " : " + pap.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintProcessorProperty": 
         var ppp = ppd.Value as System.Printing.IndexedProperties.PrintProcessorProperty; 
         sb.AppendLine(ppd.Key + " : " + ppp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintPortProperty": 
         var pportp = ppd.Value as System.Printing.IndexedProperties.PrintPortProperty; 
         sb.AppendLine(ppd.Key + " : " + pportp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintServerProperty": 
         var psvrp = ppd.Value as System.Printing.IndexedProperties.PrintServerProperty; 
         sb.AppendLine(ppd.Key + " : " + psvrp.Value); 
         break; 

        case "System.Printing.IndexedProperties.PrintDriverProperty": 
         var pdp = ppd.Value as System.Printing.IndexedProperties.PrintDriverProperty; 
         sb.AppendLine(ppd.Key + " : " + pdp.Value); 
         break; 
       } 
      } 

      sb.AppendLine(""); 
      sb.AppendLine(""); 
     } 

     System.IO.File.WriteAllText("PrinterInfo.txt", sb.ToString()); 

だからこれの終わりに、私はプリンタのようなものにつき、トップレベルのリストを取得...

PaperPort Image Printer 
SeparatorFile : 
Location : 
UntilTimeOfDay : 0 
ShareName : 
Name : PaperPort Image Printer 
Priority : 1 
AveragePagesPerMinute : 0 
UserPrintTicket : 
IsXpsEnabled : False 
DefaultPrintTicket : 
QueueStatus : None 
QueueAttributes : 65 
StartTimeOfDay : 0 
QueuePrintProcessor : System.Printing.PrintProcessor 
QueuePort : System.Printing.PrintPort 
DefaultPriority : 1 
Comment : 
Description : \\[machine]\PaperPort Image Printer,Nuance Image Printer Driver, 
HostingPrintServer : 
QueueDriver : System.Printing.PrintDriver 
NumberOfJobs : 0 

ここでも、これらのオブジェクトのいくつかは、他のオブジェクトである値が深くドリルダウンする必要がありCOMポートを取得するなどの方法もありますが、これはさらに詳細な情報にジャンプし、必要なものを見つけられるはずです。

+0

提案@DRappいただきありがとうございます。残念ながら、私は探していたパラメータを見つけることができませんでしたが、実際のソリューションを展開することができました。 Naiveは、デフォルトのプリンタを変更して各プリンタの固有の値に気づいたときにレジストリ値を調べた後、OSを切り替えるときに見たものを反映するために最後の2つのパラメータが必要であると仮定しました。理由はわかりませんが、例として「Printer Name、winspool、Ne01:」のようにしてそのまま残しておけば、プリンタの名前を変更するだけです。ちょうど私が尋ねる前にそれを試してみたかった!手伝ってくれてありがとう – Ashley

関連する問題