手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

Delphi必学技巧:枚举打印机

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

1 2 3 4 下一页

  在某些情况下,我们需要枚举网内的打印机,试试以下的代码,很有可能帮得了你。





  using System;
  using System.Runtime.InteropServices;
  using System.Runtime.Serialization;

  namespace Sample.GetPrinter
  {
  class App
  {
  static void Main(string[] args)
  {
  Console.WriteLine("请输入你想搜索类型的序号:");
  Console.WriteLine("1. Default printer(only Win95,Win98,WinME)\n2. Enumerates the locally installed printers;\n3. Enumerates the list of printers to which the user has made previous connections;\n4. Enumerates the printer identified by Name.;\n5. Enumerates network printers and print servers in the computer's domain;\n6. Enumerates printers that have the shared attribute;\n7. Enumerates network printers in the computer's domain;\n==========================");
  
  int pt =0;
  try
  {
  pt=Int32.Parse(Console.ReadLine());
  }
  catch(Exception e)
  {
  Console.WriteLine("错误信息: {0}",e.Message);
  return;
  }

  PRINTER_ENUM printerKind = GetPrinterConType(pt);

  PrinterSearcher p = new PrinterSearcher();

  PrinterSearcher.PrinterInfo[] printers = p.Search(printerKind);

  foreach(PrinterSearcher.PrinterInfo pi in printers)
  {
  Console.WriteLine("=====================================\n打印机名: {0}\n描叙:: {1}\n注释: {2}\n=====================================\n",
  pi.Name, pi.Description, pi.Comment);
  }
  }

  static PRINTER_ENUM GetPrinterConType(int ins)
  {
  switch(ins)
  {
  case 1:
  return PRINTER_ENUM.DEFAULT ;
  case 2:
  return PRINTER_ENUM.LOCAL;
  case 3:
  return PRINTER_ENUM.CONNECTIONS;
  case 4:
  return PRINTER_ENUM.NAME;
  case 5:
  return PRINTER_ENUM.REMOTE;





上一篇: Delphi 2005抢先预览
下一篇: 利用Delphi编写Socket通信程序

1 2 3 4 下一页

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!