如何在asp.net中的web应用程序中使用管理类 [英] How to use management class in web application in asp.net

查看:71
本文介绍了如何在asp.net中的web应用程序中使用管理类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试编写一个会破坏打印机状态的代码



使用System.Management; 





 ManagementScope scope = new ManagementScope(\\ root\\cimv2\" ); 

scope.Connect();

//从WMI对象集合中选择打印机

ManagementObjectSearcher searcher = new ManagementObjectSearcher(SELECT * FROM Win32_Printer);

string printerName =;

foreach(searcher.Get()中的ManagementObject打印机){

printerName = printer(Name)。ToString()。ToLower();

if(printerName.Equals(Name_Of_Printer))

{

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

if(printer(WorkOffline)。ToString()。ToLower()。Equals(true))

{

/ / printer由用户离线

Console.WriteLine(您的Plug-N-Play打印机未连接。);

}

else

{

//打印机不离线

控制台.WriteLine(你的Plug-N-Play打印机已连接。);

}
}





但我收到的错误为

 错误  54 类型 命名空间 name ' 找不到ManagementScope(你错过了吗?使用指令或程序集引用?)C:\ Users \d3 \Desktop \ Nuggetts Cloud \Project\asset_cardmstr.aspx.cs 54 6 C:\ ... \ Project \  





请帮助现在缺少的东西。?

解决方案

请看我对这个问题的评论:-)



但即使这样也没有意义,即使你真的想检测状态。使用ASP.NET,通常使用.NET,您只能检测某些服务器端打印机的状态。来吧,HTTP服务器主机通常没有打印机,或者它们没有暴露给客户;这没有道理。由于明显的原因,您的服务器端代码和Web应用程序无法直接访问用户的打印机。也许你真正需要的是原则上学习Web技术如何工作。你可以从这里开始:

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 [ ^ ]。



我建议什么?将用户的打印机留给用户。他们知道如何处理他们的打印机;相信他们。更好地提供适合打印的内容。但这是一个非常不同的故事。请参阅:

http://www.w3schools.com/css/css_mediatypes.asp [ ^ ]。







请同时查看我对相关问题的回答:

使用ASP.net打印到LPT1端口 [ ^ ],

如何在ASP.NET中获取客户端打印机列表? [ ^ ]。



-SA

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

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.??

解决方案

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


这篇关于如何在asp.net中的web应用程序中使用管理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆