远程WMI连接 [英] Remote WMI connection
问题描述
我要连接到运行Windows 7的远程PC,从本地网络使用管理范围另一台电脑。
在远程PC我创建了一个新的用户帐户塞缪尔没有密码,并设置为管理员。
ConnectionOptions选项=新ConnectionOptions();
options.Username =塞缪尔;
options.Password =;
管理范围范围=新的管理范围(\\\\192.168.0.2\\root\\cimv2选项);
scope.Connect();
的错误我得到:
访问被拒绝。 (异常来自
HRESULT:0X80070005(E_ACCESSDENIED))
块引用>
更新:结果
对于使用设置密码后,我得到新的错误:
RPC服务器不可用。
(异常来自HRESULT:0x800706BA)
块引用>
解决方案也许这是缺少EnablePrivileges
scope.Options.EnablePrivileges = TRUE;
从MSDN(的 ConnectionOptions.EnablePrivileges物业):
获取或设置指示
用户权限是否需要为连接操作启用
的值。当
进行的操作要求启用
(例如,一台机器重新启动)一个
某些用户权限应该只用于
该属性
块引用>
编辑:
。如果它不能正常工作,请尝试ImpersonationLevel设置为模拟:scope.Options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ImpersonationLevel模仿:
冒充级COM模拟
级,允许对象使用呼叫者的
凭据。这是
推荐模拟级别为
WMI调用。
块引用>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)
解决方案Maybe it's the missing 'EnablePrivileges':
scope.Options.EnablePrivileges = true;
From MSDN (ConnectionOptions.EnablePrivileges Property):
Gets or sets a value indicating whether user privileges need to be enabled for the connection operation. This property should only be used when the operation performed requires a certain user privilege to be enabled (for example, a machine restart).
Edit: If it doesn't work, try setting the ImpersonationLevel to 'Impersonate':
scope.Options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ImpersonationLevel Impersonate: Impersonate-level COM impersonation level that allows objects to use the credentials of the caller. This is the recommended impersonation level for WMI calls.
这篇关于远程WMI连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!