PDA

View Full Version : log کردن پرینتر



m_amin_t
یک شنبه 23 دی 1386, 14:58 عصر
سلام.
من میخوام عملکرد پرینتر رو log کنم. یعنی مثلا پرینتر هر چیزی رو که پرینت میگیره (از طریق هر برنامه ای) اون چیزی که پرینت گرفته شده رو یه نسخه توی برنامه م ذخیره کنه.
به نظرتون چطور میشه این کار رو انجام داد؟

mohammad272005
دوشنبه 24 دی 1386, 00:32 صبح
کد زیر رو امتحان کن:

using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PrintJob");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_PrintJob instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Caption: {0}", queryObj["Caption"]);
Console.WriteLine("DataType: {0}", queryObj["DataType"]);
Console.WriteLine("Description: {0}", queryObj["Description"]);
Console.WriteLine("Document: {0}", queryObj["Document"]);
Console.WriteLine("DriverName: {0}", queryObj["DriverName"]);
Console.WriteLine("ElapsedTime: {0}", queryObj["ElapsedTime"]);
Console.WriteLine("HostPrintQueue: {0}", queryObj["HostPrintQueue"]);
Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
Console.WriteLine("JobId: {0}", queryObj["JobId"]);
Console.WriteLine("JobStatus: {0}", queryObj["JobStatus"]);
Console.WriteLine("Name: {0}", queryObj["Name"]);
Console.WriteLine("Notify: {0}", queryObj["Notify"]);
Console.WriteLine("Owner: {0}", queryObj["Owner"]);
Console.WriteLine("PagesPrinted: {0}", queryObj["PagesPrinted"]);
Console.WriteLine("Parameters: {0}", queryObj["Parameters"]);
Console.WriteLine("PrintProcessor: {0}", queryObj["PrintProcessor"]);
Console.WriteLine("Priority: {0}", queryObj["Priority"]);
Console.WriteLine("Size: {0}", queryObj["Size"]);
Console.WriteLine("StartTime: {0}", queryObj["StartTime"]);
Console.WriteLine("Status: {0}", queryObj["Status"]);
Console.WriteLine("StatusMask: {0}", queryObj["StatusMask"]);
Console.WriteLine("TimeSubmitted: {0}", queryObj["TimeSubmitted"]);
Console.WriteLine("TotalPages: {0}", queryObj["TotalPages"]);
Console.WriteLine("UntilTime: {0}", queryObj["UntilTime"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}