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)
评论前必须登录!
注册