WMI “Printer job status “is not working in Windows service
-
Hi I am creating windows service for finding the job information using WMI.Service is installed successfully. I can start service successfully, but, when I give command to print some document. The document get s printed but that time, it does not track any job status. I am not getting printer job using ManagementObjectCollection printJobs = printJobsSeacher.Get();. I want to know how can I Get printer job staus when I use window service.I think , I am doing some mistak .Plese help me. public partial class WMIPrinterService : ServiceBase { static Timer oTimer; public const int iInterval = 200; public WMIPrinterService() { InitializeComponent(); } protected override void OnStart(string[] args) { oTimer = new Timer(new TimerCallback(Callback), this, 0, iInterval); } public void Callback(object sender) { GetStatus(); } protected override void OnStop() { } void GetStatus() { ManagementObjectSearcher printJobsSeacher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PrintJob"); ManagementObjectCollection printJobs = printJobsSeacher.Get(); foreach (ManagementObject item in printJobs) { // Print JobStatus } } } Regards Rajesh
rajesh
-
Hi I am creating windows service for finding the job information using WMI.Service is installed successfully. I can start service successfully, but, when I give command to print some document. The document get s printed but that time, it does not track any job status. I am not getting printer job using ManagementObjectCollection printJobs = printJobsSeacher.Get();. I want to know how can I Get printer job staus when I use window service.I think , I am doing some mistak .Plese help me. public partial class WMIPrinterService : ServiceBase { static Timer oTimer; public const int iInterval = 200; public WMIPrinterService() { InitializeComponent(); } protected override void OnStart(string[] args) { oTimer = new Timer(new TimerCallback(Callback), this, 0, iInterval); } public void Callback(object sender) { GetStatus(); } protected override void OnStop() { } void GetStatus() { ManagementObjectSearcher printJobsSeacher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PrintJob"); ManagementObjectCollection printJobs = printJobsSeacher.Get(); foreach (ManagementObject item in printJobs) { // Print JobStatus } } } Regards Rajesh
rajesh
Rajesh_K_Sharma wrote:
void GetStatus() { ManagementObjectSearcher printJobsSeacher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PrintJob"); ManagementObjectCollection printJobs = printJobsSeacher.Get(); foreach (ManagementObject item in printJobs) { // Print JobStatus } } }
if your run this code with out services does this get the print job status? try this
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("JobStatus: {0}", queryObj["JobStatus"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } } }
cheers, Abhijit
-
Rajesh_K_Sharma wrote:
void GetStatus() { ManagementObjectSearcher printJobsSeacher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PrintJob"); ManagementObjectCollection printJobs = printJobsSeacher.Get(); foreach (ManagementObject item in printJobs) { // Print JobStatus } } }
if your run this code with out services does this get the print job status? try this
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("JobStatus: {0}", queryObj["JobStatus"]); } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } } }
cheers, Abhijit
Hi Abhijit Thanks, I would like to implement in windows service not in console application . I already did in console and window form application.It works fine . But when I use in windows service . It don't work.
rajesh