本文介绍了如何在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 \
请帮助现在缺少的东西。?
解决方案
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.??
解决方案
这篇关于如何在asp.net中的web应用程序中使用管理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!