如何在.NET中使用WMI

yy3322 2003-12-15 10:52:23
如何在.NET中使用WMI
在.NET中如何使用System.Management这个名字空间
...全文
29 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
foxstarx 2004-02-14
  • 打赏
  • 举报
回复
在“解决方案”里引用management.dll即可
xeimm 2003-12-18
  • 打赏
  • 举报
回复
在添加引用的地方找到 management 然后添加进来
yy3322 2003-12-18
  • 打赏
  • 举报
回复
多谢了 但我在系统中使用时提示“系统中没有System.Management这个名字空间”
请问如何在.net中安装.WMI这个名字空间
longchen 2003-12-15
  • 打赏
  • 举报
回复
先在添加引用中把System.Management对象引用,使用ConnectionOptions对象连接计算机ConnectionOptions options = new ConnectionOptions();
options.Username = this.textBox2.Text;
options.Password = this.textBox3.Text;
try
{
ManagementScope conn= new ManagementScope("\\\\"+this.textBox1.Text+"\\root\\cimv2",options);
conn.Connect();
ObjectQuery oq = new ObjectQuery("select * from Win32_OperatingSystem");//操作信息

ManagementObjectSearcher query1 = new ManagementObjectSearcher(conn,oq);
ManagementObjectCollection queryCollection = query1.Get();
foreach(ManagementObject mo in queryCollection)
{
string[] ss = {""};
if(this.comboBox1.Text == "重新启动")
mo.InvokeMethod("Reboot",ss);
else if (this.comboBox1.Text == "远程关机")
mo.InvokeMethod("Shutdown",ss);
else
MessageBox.Show("请选择操作!");
}
}
catch(System.UnauthorizedAccessException error)
{
MessageBox.Show("连接"+this.textBox1.Text +"出错,出错信息:"+error.Message.ToString());
}
catch(Exception err)
{
MessageBox.Show("连接"+this.textBox1.Text +"出错,出错信息:"+err.Message.ToString());
}

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧