错误:用户凭据不能用于本地连接WMI C# [英] Error: user credentials cannot be used for local connections WMI C#

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

问题描述

我正在尝试连接远程服务器以进行Windows服务监控,但获得异常

I am trying to connect remote server for windows service monitoring but getting exception "

User credentials cannot be used for local connections



也不是确定代码有什么问题,请帮忙



我尝试过:



".
nor sure what is wrong with the code, please help

What I have tried:

ConnectionOptions con=new ConnectionOptions();
           con.Impersonation = ImpersonationLevel.Impersonate;
           con.Authentication = AuthenticationLevel.Default;
           con.Username = "admin";
           con.Password = "pass";
           con.Authority = "ntlmdomain:ServerName";
           con.EnablePrivileges = true;


           ManagementScope scope = new ManagementScope(new ManagementPath(@"\\ServerName\root\cimv2"), con);
            scope.Connect();
            ObjectQuery query=new ObjectQuery("SELECT * FROM Win32_Service WHERE Name = 'MyService'");

            ManagementObjectSearcher searcher=new ManagementObjectSearcher(scope,query);

            foreach (ManagementObject qObj in searcher.Get())
            {
                Console.Write(qObj["Status"]);
                Console.Write(" : ");
                Console.WriteLine(qObj["Status"]);
            }

推荐答案

这似乎是一个非常常见的问题。查看通过Google搜索找到的可能解决方案:用户凭据不能用于本地连接 - Google搜索 [ ^ ]
It appears to be a very common issue. Check out the possible solutions found via Google Search: User credentials cannot be used for local connections - Google Search[^]


这篇关于错误:用户凭据不能用于本地连接WMI C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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