欢迎访问!
您的支持是我们不断前行的动力!

C# 获取打印机列表,C# 设置打印机属性,C# 保留打印的文档

1,获取打印机列表:

public void SetPrinters()
{
      ManagementScope ms = new ManagementScope(ManagementPath.DefaultPath);
      ms.Connect();
      SelectQuery sq = new SelectQuery
      {
           QueryString = @"SELECT Name FROM Win32_Printer"
      };
      ManagementObjectSearcher mos =new ManagementObjectSearcher(ms, sq);
      ManagementObjectCollection oObjectCollection = mos.Get();
      foreach (ManagementObject mo in oObjectCollection)
      {
          string printer=mo["Name"].ToString();
          .....      
      }
}

2,设置打印机属性

官方说明:

https://docs.microsoft.com/en-us/powershell/module/printmanagement/set-printer

Set-Printer -Name "Microsoft XPS Document Writer" -KeepPrintedJobs $True
$Printer = Get-Printer -Name "Microsoft XPS Document Writer"
$Printer.KeepPrintedJobs = $True
Set-Printer -InputObject $Printer

3,执行powershell命令,参考 C# 调用powershell,C#执行powershell语句,C# 使用Runspace执行powershell命令 (spidersharp.com)

赞(0) 打赏
转载请注明出处,未注明出处不得转载,蜘蛛侠 » C# 获取打印机列表,C# 设置打印机属性,C# 保留打印的文档
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

蜘蛛侠,您身边的爬虫专家!

觉得文章有用就打赏一下文章作者吧

支付宝扫一扫打赏

微信扫一扫打赏