远程 WMI 连接
我想使用本地网络上的 ManagementScope 从另一台电脑连接到运行 Windows 7 的远程电脑。 在远程 PC 上,我创建了一个没有密码的新用户帐户“Samuel”,并设置为管理员。
ConnectionOptions options = new ConnectionOptions();
options.Username = "Samuel";
options.Password = "";
ManagementScope scope = new ManagementScope("\\\\192.168.0.2\\root\\cimv2", options);
scope.Connect();
我得到的错误:
访问被拒绝。 (例外情况来自 HRESULT:0x80070005(E_ACCESSDENIED))
更新:
设置使用密码后,出现新错误:
RPC 服务器不可用。 (HRESULT 异常:0x800706BA)
I want to connect to remote PC running Windows 7, from another PC using ManagementScope on a local network.
On remote PC I've created a new user account "Samuel" without password and set as administrator.
ConnectionOptions options = new ConnectionOptions();
options.Username = "Samuel";
options.Password = "";
ManagementScope scope = new ManagementScope("\\\\192.168.0.2\\root\\cimv2", options);
scope.Connect();
The Error I get:
Access is denied. (Exception from
HRESULT: 0x80070005 (E_ACCESSDENIED))
Update:
After setting password for the use, I get new error:
The RPC server is unavailable.
(Exception from HRESULT: 0x800706BA)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
也许是缺少“EnablePrivileges”:
来自 MSDN (ConnectionOptions. EnablePrivileges 属性):
编辑:
如果不起作用,请尝试将 ImpersonationLevel 设置为“Impersonate”:
Maybe it's the missing 'EnablePrivileges':
From MSDN (ConnectionOptions.EnablePrivileges Property):
Edit:
If it doesn't work, try setting the ImpersonationLevel to 'Impersonate':
根据 TechNet 上的 WMI 常见问题解答,0x80070005 错误表示DCOM 问题:
<块引用>
0x80070005(DCOM ACCESS_DENIED)
当连接的用户无法识别或受到远程服务器以某种方式限制(例如,用户可能被锁定)时,会发生此错误。当帐户位于不同域时,这种情况最常发生。最近对 WMI 安全性的更改也可能导致发生此错误:
Windows XP 和 Windows Server 2003 中不允许使用以前允许的空白密码。
WMI 不允许对 Windows 98 客户端进行异步回调。从 Windows 98 计算机到 Windows XP 计算机的 SWbemServices.ExecNotificationQueryAsync 调用将导致 Windows 98 计算机返回“拒绝访问”错误。
DCOM 配置访问设置可能已更改。
如果目标计算机运行的是 Windows XP,则注册表项 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa 下的 Forceguest 值可能会设置为强制关闭来宾帐户(值为零)。
(虽然提到了 Windows XP,但这也可能适用于 Windows 7。)
0x800706BA 错误在其运行中表示防火墙问题:
<块引用>
0x800706xx(DCOM RPC 错误)
当远程计算机上配置了防火墙时,通常会发生这种情况。您需要在防火墙上打开适当的端口以允许使用 DCOM 进行远程管理。
尝试在远程计算机上的 Windows 防火墙中启用远程管理例外,看看是否有帮助。要从命令行执行此操作,请在提升的命令提示符中运行以下命令:
您还可以在 MSDN 上的“从 Windows Vista 开始远程连接到 WMI”文章。
此外,由于 Samuel 是非域帐户,因此您需要授予此帐户 DCOM 远程访问、远程启动 和 <远程计算机上的远程激活权限,如此处< /a>.
According to the WMI FAQ on TechNet, the 0x80070005 error indicates a DCOM issue:
(Although Windows XP is mentioned, this may be applied to Windows 7 as well.)
The 0x800706BA error, in its rurn, indicates a firewall issue:
Try enabling the Remote administration exception in Windows Firewall on the remote computer and see if it helps. To do this from the command line, run the following command in the elevated command prompt:
You can also find the DCOM, UAC, Windows Firewall and other settings required for remote WMI access in the Connecting to WMI Remotely Starting with Windows Vista article on MSDN.
Also, since Samuel is a nondomain account, you need to grant this account DCOM Remote Access, Remote Launch and Remote Activation permissions on the remote computer as described here.
您收到“访问被拒绝”的信息。因为您无法仅使用用户名查询作用域连接。您有 2 个选项:用户名和密码为 null 或输入用户名和密码。
您收到“RPC 服务器不可用”。因为防火墙不允许您查询该机器。您有 2 个选择:禁用防火墙或向其添加远程管理例外。
您可以在cmd中像这样添加防火墙例外:
较旧的 Windows 版本:
较新的 Windows 版本:
如果您尝试使用域用户登录,请将用户名更改为
domainName\username
或设置连接属性connection.Authority =“ ntlmdomain:域名"
。You got "Access is denied." because you cannot query scope connection with username only. You have 2 options: null for username and password or enter username and password.
You got "The RPC server is unavailable." because firewall doesn't let you query that machine. You have 2 options: disable firewall or add remote administration exception to it.
You can add firewall exception like this in cmd:
Older windows versions:
Newer windows versions:
If you try to login with domain user, change username to
domainName\username
or set connection propertyconnection.Authority = "ntlmdomain:domainName"
.您确定可以在没有密码的情况下与帐户建立远程 WMI 连接吗?
此类帐户无法执行许多操作(例如共享文件、远程桌面)。尝试设置密码,看看是否有影响。
Are you sure you can make remote WMI connections to accounts without passwords?
There are a number of things such accounts can't do (share files, remote desktop, for example). Try setting a password and see if that makes a difference.
您可能需要检查远程 Windows 7 PC 上的 WMI 安全设置。
右键单击计算机>管理>服务和应用> WMI控制>安全选项卡
并确保您使用的用户帐户具有 necc 权限。
You may want to check to WMI Security Settings on the Remote Windows 7 PC.
Right Click Computer > Manage > Services and Applications > WMI Control > Security Tab
and make sure the user account you are using has the necc permissions.
不确定是否因为 WMI 引擎未在远程计算机上侦听而被拒绝,或者是否存在其他登录/连接问题。
这是我用来连接到远程计算机的代码,它运行良好。也许它会对您有所帮助:
如果我的域名/登录名/密码三重奏被接受,那么 Connect() 将起作用。否则,Connect() 会引发异常。只要指定的凭据在该计算机上具有权限,您就应该关闭并运行。
Not sure if it is denied because the WMI engine isn't listening on the remote machine, or if you have other login/connection issues.
Here's the code I used to connect to my remote machine, and it is working perfectly. Maybe it will help you:
If my domain/login/password trio are accepted, then Connect() will work. Otherwise, Connect() throws an exception. As long as the specified credentials have permission on that machine, you should be off and running.
尝试在用户名前添加域名或计算机名称(例如@“mshome\Samuel”)。
Try to add domain or computer name before the username (e.g. @"mshome\Samuel").
使用“net view \\servername”的解决方案
我知道使用控制台命令并对输出执行一些字符串操作不是很理想,但另一方面它确实有效并且不是很理想或者,至少对我来说,必须修改 DCOM 默认设置才能让 WMI 方式工作(至少在 Win7s 上)。
已在 Win7 和 XP 客户端以及 MS 和 Linux 服务器上进行了测试。
Solution using "net view \\servername"
I know it's not very desirable to use a console command and do some string-gymnastic on the output, but on the other hand it does work and it's not very desirable either, at least for me, to have to mess around with the DCOM default settings to to get the WMI way to work (at least on Win7s).
Has been tested on Win7 and XP clients and MS- and linux server.
我也遇到了这个问题。我试图编写 C# 代码来从远程 PC 获取 WMI 信息和文件。并遇到了两个
访问被拒绝
错误:长话短说,我必须对远程电脑进行更改。见下文:
I had this problem too.I was trying to write C# code to get WMI information and files from a remote PC. And ran into two
Access Denied
errors:To keep a long story short, I had to make changes to the remote PC. See below: