2012-03-16 42 views
1

是否有一种可靠的方法来确定Microsoft XPS Document Writer是否在系统上通过.Net可用并且功能正常?有没有办法确定Microsoft XPS Document Writer在系统上是否可用并且正常工作

此外,在所有Windows发行版(例如英语,德语(...))上,XPS Writer的名称是否相同?

自Vista以来,XPS Writer是否可在所有Windows系统上明确提供。还在Starter Editions,所有x86和x64版本以及Windows 8上?

+1

这个名字绝对不可靠。用户可以随时重命名“Microsoft XPS Document Writer”打印队列。 – Jon 2012-03-16 15:55:27

回答

0

看看http://msdn.microsoft.com/en-us/library/aa969772.aspx

我怀疑你可以用下面的代码片段,试图打印XPS,那么如果它不工作,你可能没有一台打印机。

  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 2016-02-12 19:58:02

1

我不知道名称,但“打印机”的型号也是Microsoft XPS Document Writer,并且保持不变。

您可以使用该型号寻找打印机!

+1

看起来模型实际上是打印机驱动程序的名称,可以通过PrintQueue.QueueDriver.Name获取。 – 2012-04-12 14:21:23

0

至于建议由彼得Witvoet,这里是如果是基于驱动程序名称安装或不XPSPrinter返回的方法。

该方法循环打印机,直到它找到一个或它已扫描每一个没有找到一个。 需要在项目中添加对“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; 
    } 

编辑:我发现驱动程序名称可以是错误的一段时间。它可能是“远程桌面轻松打印”,而不是XPS打印机和其他一些非XPS打印机。因此,检查DeviceID是否包含XPS是一种更安全的方法。

相关问题