Search results for 'ManagementObject'. 1 post(s) found.
This code will test whether a Printer is connected to your system or not. It works with USB and network Printers (haven't tested LPT Printers yet). Some Printers (like my HP DeskJet 930c) is detected online even though I press the OFF button (as long as the power adaptor is switched ON). This is true,as the Printer is able to switch on itself when the Print queue is not empty. But if I switch off the power adaptor,then the Printer cannot switch on itself,and Windows automatically adjusts the Printer setting by checking the "Use Printer Offline" in the Printer Control Panel. Same case with network Printers. When I plug my network cable,Windows automatically unchecks the "Use Printer Offline",and when I unplug it,Windows rechecks the "Use Printer Offline". This is what my code detects,whether "Use Printer Offline" is actually checked or not.
using System;
using System.Management;
namespace kurapa.com
{
class PrinterOffline
{
[STAThread]
static void Main(string[] args)
{
// Set management scope
ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string PrinterName = "";
foreach (ManagementObject Printer in searcher.Get())
{
PrinterName = Printer["Name"].ToString().ToLower();
if (PrinterName.Equals(@"hp deskjet 930c"))
{
Console.WriteLine("Printer = " Printer["Name"]);
if (Printer["WorkOffline"].ToString().ToLower().Equals("true"))
{
// Printer is offline by user
Console.WriteLine("Your PnP Printer is not connected.");
}
else
{
// Printer is not offline
Console.WriteLine("Your PnP Printer is connected.");
}
}
}
}
}
}
using System.Management;
namespace kurapa.com
{
class PrinterOffline
{
[STAThread]
static void Main(string[] args)
{
// Set management scope
ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string PrinterName = "";
foreach (ManagementObject Printer in searcher.Get())
{
PrinterName = Printer["Name"].ToString().ToLower();
if (PrinterName.Equals(@"hp deskjet 930c"))
{
Console.WriteLine("Printer = " Printer["Name"]);
if (Printer["WorkOffline"].ToString().ToLower().Equals("true"))
{
// Printer is offline by user
Console.WriteLine("Your PnP Printer is not connected.");
}
else
{
// Printer is not offline
Console.WriteLine("Your PnP Printer is connected.");
}
}
}
}
}
}
Another posts included in "C#"
| Simplified .NET Printing In C# (0) | 2007/08/28 |
| A Customizable Printing Text Class (0) | 2007/08/28 |
| Print HTML In C# With Or Without The Web Browser Control And The Print... (0) | 2007/08/28 |
| How To Print Text In C# (0) | 2007/08/28 |
| C Sharp Lists (0) | 2007/08/28 |
| Simple Example Of IF/THEN Using C# (0) | 2007/08/28 |
| Simple C# CGI working on Apache (0) | 2007/08/27 |
| How to send binary data through C# CGI app? (0) | 2007/08/27 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 03:35
moneyideas
-
Subject different money making ideas
2010/01/29 12:25
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas

Prev

Rss Feed