Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WMI “Printer job status “is not working in Windows service

WMI “Printer job status “is not working in Windows service

Scheduled Pinned Locked Moved C#
helpquestioncareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajesh_K_Sharma
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • R Rajesh_K_Sharma

      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

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • A Abhijit Jana

        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

        R Offline
        R Offline
        Rajesh_K_Sharma
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups