How to get the list of all printers in computer

前端 未结 6 1070
长发绾君心
长发绾君心 2020-11-29 17:58

I need to get the list of all printers that connect to computer?

How I can do it in C#, WinForms?

6条回答
  •  春和景丽
    2020-11-29 18:45

    You can also use the LocalPrintServer class. See: System.Printing.LocalPrintServer

        public List  InstalledPrinters
        {
            get
            {
                return (from PrintQueue printer in new LocalPrintServer().GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,
                    EnumeratedPrintQueueTypes.Connections }).ToList()
                        select printer.Name).ToList(); 
            } 
        }
    

    As stated in the docs: Classes within the System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service.

提交回复
热议问题