Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Determine Which Printers are Connected using WMI
    primarykey
    data
    text
    <p>I've been trying to find a way to figure out which installed printers are 'connected'. After some Googling I figured I had to dive into WMI.</p> <p>So I've built this test:</p> <pre><code>// Struct to store printer data in. public struct MyPrinter { public string Availability; public string ExtendedPrinterStatus; public string Name; public string PrinterStatus; public string Status; public string StatusInfo; public MyPrinter(string a, string eps, string n, string ps, string s, string si) { Availability = a; ExtendedPrinterStatus = eps; Name = n; PrinterStatus = ps; Status = s; StatusInfo = si; } } var installedPrinters = new string[numPrinters]; PrinterSettings.InstalledPrinters.CopyTo(installedPrinters, 0); var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"); var data = new List&lt;MyPrinter&gt;(); foreach (var printer in searcher.Get()) { if (installedPrinters.Contains(printer["Name"].ToString())) { var availability = (printer["Availability"] ?? "").ToString(); var extendedPrinterStatus = (printer["ExtendedPrinterStatus"] ?? "").ToString(); var name = (printer["Name"] ?? "").ToString(); var printerStatus = (printer["PrinterStatus"] ?? "").ToString(); var status = (printer["Status"] ?? "").ToString(); var statusInfo = (printer["StatusInfo"] ?? "").ToString(); data.Add(new MyPrinter(availability, extendedPrinterStatus, name, printerStatus, status, statusInfo)); } } </code></pre> <p>I have 6 printers from which 2 are network printers. I've run this with all printers connected and all results looked like this:</p> <pre><code>Availability = "" // printer["Availability"] = null ExtendedPrinterStatus = "2" // 2 = Unknown Name = "{printer name here}" PrinterStatus = "3" // 3 = Idle Status = "Unknown" StatusInfo = "" // Null </code></pre> <p>So the only difference between the printers is the name. I ran the script again but this time I disconnected my laptop from the network. So 2 of the printers were not connected anymore in this case.</p> <p>The strange thing (for me) is, the results were exactly the same.</p> <p>The reason I ran this test is, to figure out which field I'd need to use for my case.</p> <p>So at the end, I have not been able to figure out how to figure out if a printer is connected or not. So what I'd like, is a way to figure out the installed + connected printers in C#. If there is a way to do it without the use of WMI classes, that's also fine by me, as long as it works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload