WMI 访问被拒绝 excptn

发布于 2024-08-15 12:47:37 字数 1277 浏览 2 评论 0原文

 string s = Form1.ipadd;
            string devic;
            devic = comboBox1.Text;
            groupBox2.Text = devic + "  Information";
            ConnectionOptions _Options = new ConnectionOptions();
            _Options.Username = "Babar";
            _Options.Password = "";
            ManagementPath _Path = new ManagementPath(s);

            ManagementScope _Scope = new ManagementScope(_Path, _Options);
            _Scope.Connect();
            ManagementObjectSearcher srcd = new ManagementObjectSearcher("select * from "+devic);
            tsprogress.Value = 0;
            Allplabel.Text = " : 0%";
            foreach (ManagementObject obj in srcd.Get())
            {


                //listBox5.Items.Add(obj.Properties.ToString());
                foreach (PropertyData aProperty in obj.Properties)
                {
                    i++;
                    tsprogress.Value = (i / cont) * 100;
                    Allplabel.Text = tsprogress.Value.ToString() + "%";
                    richTextBox1.AppendText(aProperty.Name.ToString() + " : " + aProperty.Value+"\n");


                }

            }

////////////////////////////////////////////////// 上面的代码在本地主机上工作正常,但在访问远程系统时不起作用......访问被拒绝例外......我将非常感谢2你的帮助。

 string s = Form1.ipadd;
            string devic;
            devic = comboBox1.Text;
            groupBox2.Text = devic + "  Information";
            ConnectionOptions _Options = new ConnectionOptions();
            _Options.Username = "Babar";
            _Options.Password = "";
            ManagementPath _Path = new ManagementPath(s);

            ManagementScope _Scope = new ManagementScope(_Path, _Options);
            _Scope.Connect();
            ManagementObjectSearcher srcd = new ManagementObjectSearcher("select * from "+devic);
            tsprogress.Value = 0;
            Allplabel.Text = " : 0%";
            foreach (ManagementObject obj in srcd.Get())
            {


                //listBox5.Items.Add(obj.Properties.ToString());
                foreach (PropertyData aProperty in obj.Properties)
                {
                    i++;
                    tsprogress.Value = (i / cont) * 100;
                    Allplabel.Text = tsprogress.Value.ToString() + "%";
                    richTextBox1.AppendText(aProperty.Name.ToString() + " : " + aProperty.Value+"\n");


                }

            }

/////////////////////////
The above code works fine on local host but does not works while accessing remote system......Accesses denied excption ...i shall b very thankful 2 your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2024-08-22 12:47:37

运行此代码的帐户必须在远程计算机上具有足够的访问权限。请参阅此 MSDN 页面。它还展示了如何使用模拟,这可能是解决您的问题的一种方法。

The account that is running this code must have sufficient access on the remote machine. See this MSDN page. It also shows how to use impersonation, that may be a way to solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文