如何清除异常,用户凭据不能用于WMI中的本地连接 [英] how to clear the Exception ,User credentials cannot be used for local connections in WMI

查看:885
本文介绍了如何清除异常,用户凭据不能用于WMI中的本地连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我想显示本地计算机上远程服务器的共享文件夹列表,但是我遇到异常(用户凭据无法用于本地连接),请多多帮助.我的代码.
谢谢U ...........


Friends i want to display the list of shared folders from a remote server in a local machine but i am getting Exception(User credentials cannot be used for local connections) Any help would be appreciated .......here is my code..
Thank U...........


System.Management.ManagementScope ms1 = new System.Management.ManagementScope();
            
            ms1.Options.Username = "pavan";
            ms1.Options.Password = "welcome";

            using (System.Management.ManagementClass exportedShares = new     System.Management.ManagementClass(ms1, new ManagementPath("\\\\servername\\root\\cimv2:Win32_Share"), null))
            {
                System.Management.ManagementObjectCollection shares = exportedShares.GetInstances();
                foreach (System.Management.ManagementObject share in shares)
                {
                    Response.Write("Name: " + share["Name"].ToString());
                }
            }

推荐答案

您是否尝试过不使用用户凭据. br/>

Have you tried without using the user credentials.. Just comment the userid pwd and try.. the following code works for me..


System.Management.ManagementScope ms1 = new System.Management.ManagementScope();
           // ms1.Options.Username = "";
           // ms1.Options.Password = "";
            using (System.Management.ManagementClass exportedShares = new System.Management.ManagementClass(ms1, new ManagementPath("\\\\machinename\\root\\cimv2:Win32_Share"), null))
            {
                System.Management.ManagementObjectCollection shares = exportedShares.GetInstances();
                foreach (System.Management.ManagementObject share in shares)
                {
                    Response.Write("Name: " + share["Name"].ToString());
                }
            }


尝试一下:

Try with this:

ms1.Options.Authority = string.Format("NTLMDOMAIN:{0}", txtDomain.Text);
ms1.Options.Impersonation = ImpersonationLevel.Impersonate;


这篇关于如何清除异常,用户凭据不能用于WMI中的本地连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆