I'm trying to make an application that monitors my printer and when the user sends an impression, of whatever program, it captures that information, pauses the printing and opens a new window for the user to enter a code. If the code is correct it continues printing. Otherwise, the printout is canceled.
At the moment I'm just trying to get the application to pause printing. I can have it monitor the spool and return the submitted job information. I have tried to use InvokeMethod ("Pause") but it only appears that there is no such option.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
namespace Listar_Servicos
{
public partial class frmMonitor : Form
{
public frmMonitor()
{
InitializeComponent();
}
private void frmMonitor_Load(object sender, EventArgs e)
{
EventWatch("localhost");
}
private ManagementEventWatcher manEWatch;
public void EventWatch(string host)
{
ManagementScope oMs = new ManagementScope(@"\" + host + @"\root\cimv2");
oMs.Connect();
manEWatch = new ManagementEventWatcher(oMs, new EventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 0.1 WHERE TargetInstance ISA 'Win32_PrintJob'"));
manEWatch.EventArrived += new EventArrivedEventHandler(mewPrintJobs_EventArrived);
manEWatch.Start();
}
static void mewPrintJobs_EventArrived(object sender, EventArrivedEventArgs e)
{
foreach (PropertyData prop in e.NewEvent.Properties)
{
string val = prop.Value == null ? "null" : prop.Value.ToString();
}
ManagementBaseObject printJob = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value;
string v = "";
foreach (PropertyData propp in printJob.Properties)
{
string name = propp.Name;
string val = propp.Value == null ? "null" : propp.Value.ToString();
val += "\n";
v += name + ":" + val;
}
MessageBox.Show(v);
}
private void btnNovoMonitor_Click(object sender, EventArgs e)
{
frmMonitor2 novoMonitor = new frmMonitor2();
novoMonitor.Show();
}
}
}
Could anyone help me?