Druckaufträge mit WMI auslesen
Dem Projekt muss ein Verweis auf System.Management hinzugefügt werden!
// Verweis auf System.Management mus dem Projekt hinzugefügt werden
// using System.Management;
// using System.Collections.Generic;
/// <summary>
/// Get all Print Jobs
/// </summary>
/// <returns>List<PrintJob></returns>
private List<PrintJob> GetPrinterJobs()
{
string wmiQuery = "SELECT * FROM Win32_PrintJob";
ManagementObjectSearcher jobsSearcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection jobCollection = jobsSearcher.Get();
List<PrintJob> printJobs = new List<PrintJob>();
foreach (ManagementObject mo in jobCollection)
{
PrintJob printJob = new PrintJob();
printJob.Caption = (string)mo["Caption"];
printJob.DataType = (string)mo["DataType"];
printJob.Description = (string)mo["Description"];
printJob.Document = (string)mo["Document"];
printJob.DriverName = (string)mo["DriverName"];
printJob.ElapsedTime = (string)mo["ElapsedTime"];
printJob.HostPrintQueue = (string)mo["HostPrintQueue"];
printJob.InstallDate = (string)mo["InstallDate"];
printJob.JobId = Convert.ToUInt32( mo["JobId"]);
printJob.JobStatus = (string)mo["JobStatus"];
printJob.Name = (string)mo["Name"];
printJob.Notify = (string)mo["Notify"];
printJob.Owner = (string)mo["Owner"];
printJob.PagesPrinted = Convert.ToUInt32(mo["PagesPrinted"]);
printJob.Parameters = (string)mo["Parameters"];
printJob.PrintProcessor = (string)mo["PrintProcessor"];
printJob.Priority = Convert.ToUInt32(mo["Priority"]);
printJob.Size = Convert.ToUInt32(mo["Size"]);
printJob.StartTime = (string)mo["StartTime"];
printJob.Status = (string)mo["Status"];
printJob.StatusMask = Convert.ToUInt32(mo["StatusMask"]);
printJob.TimeSubmitted = (string)mo["TimeSubmitted"];
printJob.TotalPages = Convert.ToUInt32(mo["TotalPages"]);
printJob.UntilTime = (string)mo["UntilTime"];
}
return printJobs;
}
class PrintJob
{
public string Caption;
public string DataType;
public string Description;
public string Document;
public string DriverName;
public string ElapsedTime;
public string HostPrintQueue;
public string InstallDate;
public uint JobId;
public string JobStatus;
public string Name;
public string Notify;
public string Owner;
public uint PagesPrinted;
public string Parameters;
public string PrintProcessor;
public uint Priority;
public uint Size;
public string StartTime;
public string Status;
public uint StatusMask;
public string TimeSubmitted;
public uint TotalPages;
public string UntilTime;
}
Kommentare zum Snippet