日期:2014-05-18 浏览次数:21295 次
void Button1Click(object sender, EventArgs e)
        {
            ManagementObjectSearcher mos=new ManagementObjectSearcher("select * from win32_logicaldisk");
            mos.Scope.Options.Username="xpclient";
            mos.Scope.Options.Password="MZD";
            mos.Scope.Path.Server="192.168.1.15";
                        //调用这个无惨的Get方法可以
            foreach(ManagementObject mo in mos.Get())
            {
                MessageBox.Show(mo["name"].ToString());
            }
            
                        //下面这种方法居然就拒绝访问了
            ManagementOperationObserver moo=new ManagementOperationObserver();
            moo.ObjectReady+= delegate(object ssender, ObjectReadyEventArgs se)
            {
                MessageBox.Show(se.NewObject["name"].ToString());
            };
                        //在Get方法这里抛出异常,拒绝访问,是异步调用的原因吗?
            mos.Get(moo);
                        //如果是本机计算机,两种方式都成功了
        }
ConnectionOptions. connection_wmi = new ConnectionOptions(); connection_wmi.Username = ""; connection_wmi.Password = ""; connection_wmi.Authority = "ntlmdomain:DOMAIN";
------解决方案--------------------
打错了,纠正一下:
ConnectionOptions connection_wmi = new ConnectionOptions(); connection_wmi.Username = ""; connection_wmi.Password = ""; connection_wmi.Authority = "ntlmdomain:DOMAIN";
------解决方案--------------------
moo是否也应该有:
moo.Scope.Options.Username="xpclient";
moo.Scope.Options.Password="MZD";
moo.Scope.Path.Server="192.168.1.15";
另外:connection_wmi.Authority = "ntlmdomain:DOMAIN";
在NT系统下是需要的。
------解决方案--------------------