这是MSDN的提示:CancelAllJobs Method of the Win32_Printer Class Requirements Client Requires Windows "Longhorn" or Windows XP. Server Requires Windows Server "Longhorn" or Windows Server 2003. MOF Declared in Cimwin32.mof.
DLL Requires Cimwin32.dll. Namespace Defined in \root\cimv2. 这是网址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp
using System.Management; private ManagementObjectSearcher query;
private ManagementObjectCollection queryCollection;
string _classname="SELECT * FROM Win32_Printer"; query=new ManagementObjectSearcher(_classname);
queryCollection = query.Get(); foreach (ManagementObject mo in queryCollection)
{
if (string.Compare(mo["Name"].ToString(),PrinterName,true)==0)
{
mo.InvokeMethod("SetDefaultPrinter",null); //调用了其方法,可修改此处获取相关状态属性
break;
}
}
相同的方法,你在得到具体的打印机实例时,可以获取到其相关属性,再显示出来即可。
{
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.EnablePrivileges = true; ManagementScope mc = new ManagementScope(@"\ROOT\CIMV2", co);
ObjectQuery oQuery = new ObjectQuery("Select * from Win32_PrintJob");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(mc, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach( ManagementObject oReturn in oReturnCollection )
{
oReturn.InvokeMethod("CancelAllJobs",null);
}
}
错误信息如下:其他信息: 没有任何类别中执行这个方法
Requirements
Client Requires Windows "Longhorn" or Windows XP.
Server Requires Windows Server "Longhorn" or Windows Server 2003.
MOF Declared in Cimwin32.mof.
DLL Requires Cimwin32.dll.
Namespace Defined in \root\cimv2.
这是网址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp