2012-03-16 11 views
1

Microsoft XPSドキュメントライターが.Net経由でシステム上で利用可能で機能しているかどうかを判断する信頼できる方法はありますか?Microsoft XPSドキュメントライターが利用可能で、システム上で機能しているかどうかを判断する方法はありますか

また、XPS Writerの名前はすべてのWindowsディストリビューションで同じですか(英語、ドイツ語(...))?

Vista以降、すべてのWindowsシステムでXPS Writerを使用できますか。 Starter Editions、すべてのx86およびx64 Edition、Windows 8でも同様ですか?

+1

名前は間違いなく信頼できません。ユーザーはいつでも「Microsoft XPS Document Writer」プリントキューの名前を変更することができます。 – Jon

答えて

0

は、私はあなたはそれが動作しない場合、その後、あなたはおそらくプリンタを持っていない、XPSを試してみて、印刷するには、以下のスニペットを使用することができます疑うhttp://msdn.microsoft.com/en-us/library/aa969772.aspx

を見てみましょう。

  try 
      { 
       // Print the Xps file while providing XPS validation and progress notifications. 
       PrintSystemJobInfo xpsPrintJob = defaultPrintQueue.AddJob(f.Name, nextFile, false); 
      } 
      catch (PrintJobException e) 
      { 
       Console.WriteLine("\n\t{0} could not be added to the print queue.", f.Name); 
       if (e.InnerException.Message == "File contains corrupted data.") 
       { 
        Console.WriteLine("\tIt is not a valid XPS file. Use the isXPS Conformance Tool to debug it."); 
       } 
       Console.WriteLine("\tContinuing with next XPS file.\n"); 
      } 
+0

リンクが壊れています – AXMIM

1

「プリンタ」のモデルもMicrosoft XPS Document Writerで、その名前は同じですが、その名前はわかりません。

あなたはそのモデルでプリンタを探すことができます。

+1

モデルは実際にはPrintQueue.QueueDriver.Nameで取得できるプリンタドライバの名前のようです。 –

0

のPieter Witvoetによって示唆されるように、ここでXPSPrinterがインストールまたはドライバ名に基づいていない場合に返す方法があります。

このメソッドは、プリンタを見つけるまで、または1つを見つけずにすべてのものをスキャンします。 "System.Management"への参照をプロジェクトに追加する必要があります。

private bool GetIfXPSPrinterIsInstalled() 
    { 
     bool isXPSPrinterMissing = true; 
     try 
     {    
      var printerQuery = new System.Management.ManagementObjectSearcher("SELECT * from Win32_Printer"); 
      var iterator = printerQuery.Get().GetEnumerator(); 
      while (iterator.MoveNext() && isXPSPrinterMissing) 
      { 
       //isXPSPrinterMissing = iterator.Current.GetPropertyValue("DriverName").ToString() != "Microsoft XPS Document Writer"; 
       isXPSPrinterMissing = !iterator.Current.GetPropertyValue("DeviceID").ToString().ToUpper().Contains("XPS"); 
      } 
      if (isXPSPrinterMissing) 
      { 
       MessageBox.Show("Warning, there is no XPS printer installed on this computer"); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("System couldn't verify if there is a XPS printer installed because an error occured");    
     } 
     return !isXPSPrinterMissing; 
    } 

EDIT:私はドライバ名がいくつかの時間間違っている可能性があることが分かりました。これは、XPSプリンタやその他のxps以外のプリンタではなく、「Remote Desktop Easy Print」である可能性があります。したがって、DeviceIDにXPSが含まれているかどうかを確認する方が安全です。

関連する問題