问题描述
亲爱的专家,
请您指导该错误的原因
错误2 找不到类型或名称空间名称'NetworkAdapter'(您是否缺少using指令或程序集引用?)
Error 2 The type or namespace name 'NetworkAdapter' could not be found (are you missing a using directive or an assembly reference?)
String disablednic()
{
字符串计算机名;
computername = txtcomputernm.Text.ToString();
String disablednic()
{
string computername;
computername = txtcomputernm.Text.ToString();
ManagementScope范围=新的ManagementScope(String.Format("",计算机名));
scope.Connect();
SelectQuery查询=新的SelectQuery("Win32_NetworkAdapter","NetConnectionStatus = 2");
ManagementObjectSearcher搜索=新的ManagementObjectSearcher(query);
foreach(ManagementObject结果在search.Get()中)
{
NetworkAdapter适配器=新的NetworkAdapter(结果);
ManagementScope scope = new ManagementScope(String.Format("", computername));
scope.Connect();
SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
foreach (ManagementObject result in search.Get())
{
NetworkAdapter adapter = new NetworkAdapter(result);
if(adapter.AdapterType.Equals("Ethernet 802.3"))
{
adapter.Disable();
}
}
if (adapter.AdapterType.Equals("Ethernet 802.3"))
{
adapter.Disable();
}
}
}
}
推荐答案
这篇关于C#禁用远程计算机网络适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!