Frage

Normally, in old version Windows (98 or older) I can use MarkingTechnology in Printer api to get current type of printer. But it doesn't available in Windows 2000 or later. Do you have any other way to detect it in Windows 2000 or later?

Example code for query printer information via WMI Query in C#

var queryResult = string.Empty;
var query = new WqlObjectQuery("Select * from Win32_Printer");
var searcher = new ManagementObjectSearcher(query);

foreach (ManagementObject printer in searcher.Get())
{
    foreach (var p in printer.Properties)
    {
        queryResult += p.Name + ": " + printer[p.Name] + Environment.NewLine;
    }

    queryResult += "--------------------------------" + Environment.NewLine;
}

Win32_Printer class documentation

Thanks,

War es hilfreich?

Lösung

Short answer: No, there does not seem to be a consistent way to do this.

Andere Tipps

I do my best to find out the possible way to detect Dot Matrix printer. I try to call GetDeviceCaps function (retrieves device-specific information for the specified device.) to get TECHNOLOGY item that should return as Character stream if selected printer is Dot Matrix.

var hdc = CreateDC("WINSPOOL", printerName, null, IntPtr.Zero);
var technology = (DeviceCapTechnology)GetDeviceCaps(hdc, (int)DeviceCap.TECHNOLOGY);

However, it always return TECHNOLOGY item as Raster display. I don't know why it always return value like this.

[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

[DllImport("gdi32.dll")]
static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);

GetDeviceCaps function

Example Project

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top