gpt4 book ai didi

c# - 远程 WMI 连接

转载 作者:太空狗 更新时间:2023-10-29 17:32:19 25 4
gpt4 key购买 nike

我想从本地网络上使用 ManagementScope 的另一台 PC 连接到运行 Windows 7 的远程 PC。在远程 PC 上,我创建了一个没有密码的新用户帐户“Samuel”并设置为管理员。

ConnectionOptions options = new ConnectionOptions();
options.Username = "Samuel";
options.Password = "";

ManagementScope scope = new ManagementScope("\\\\192.168.0.2\\root\\cimv2", options);
scope.Connect();

我得到的错误:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

更新:
设置使用密码后,出现新错误:

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

最佳答案

也许是缺少“EnablePrivileges”:

scope.Options.EnablePrivileges = true;

来自 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).

编辑:如果它不起作用,请尝试将 ImpersonationLevel 设置为“模拟”:

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.

关于c# - 远程 WMI 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3289471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com