COM方式:使用Winspool.drv
WMI方式:Class=Win32_ Printer 另注(Powershell中可以 gwmi -Class "Win32_Printer"找到List )
C#实现
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Runtime.InteropServices;
namespace MyConsoleApp.Code
{
/// <summary>
/// 设置或者获取默认打印机类
/// </summary>
public class PrintHelper
{
#region DllImport
[DllImport("Winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string printerName);
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int pcchBuffer);
public static string GetDefaultPrinter()
{
const int ERROR_FI