Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to write a code which will defect printer status

using System.Management;


 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("Name_Of_Printer"))

{

Console.WriteLine("Printer = " + printer("Name"));

if (printer("WorkOffline").ToString().ToLower().Equals("true"))

{

// printer is offline by user

Console.WriteLine("Your Plug-N-Play printer is not connected.");

}

else

{

// printer is not offline

Console.WriteLine("Your Plug-N-Play printer is connected.");

}
} 


But i am getting error as
VB
Error   54  The type or namespace name 'ManagementScope' could not be found (are you missing a using directive or an assembly reference?)   C:\Users\d3\Desktop\Nuggetts Cloud\Project\asset_cardmstr.aspx.cs  54  6   C:\...\Project\


Please help what is missing now.??
Posted
Updated 25-Apr-17 9:49am
Comments
Sergey Alexandrovich Kryukov 22-Oct-12 14:22pm    
This is not a problem to defect a printer status. Sometimes a bigger hammer would be enough. :-)
--SA

1 solution

Please see my comment to the question :-)

But even this would make no sense, even if you actually wanted to detect the status. With ASP.NET, with .NET in general, you can only detect the status of some server-side printer. Come on, the HTTP server hosts usually don't have printer, or they are not exposed to the customers; it makes no sense. And your server-side code and your Web application does not have direct access to user's printers, by apparent reasons. Perhaps what you really need is learning how Web technically works, in principle. You could start here:
http://en.wikipedia.org/wiki/HTTP[^],
http://en.wikipedia.org/wiki/Web_server[^],
http://en.wikipedia.org/wiki/Web_browser[^],
http://en.wikipedia.org/wiki/WWW[^].

What would I advise? Leave the users' printers to users. They know what to do with their printers; trust them. Better provide printer-friendly content. But this is a very different story. Please see:
http://www.w3schools.com/css/css_mediatypes.asp[^].

[EDIT]

Please also see my answers to a related questions:
Print to LPT1 port using ASP.net[^],
How to get client side printer list in ASP.NET?[^].

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900