繁体   English   中英

当前登录用户在远程计算机上的WMI模拟

[英]wmi impersonation on remote computer as currently logon user

我已经创建了mvc应用程序。 这是一个Intranet网站。 用户使用Windows身份验证登录。 经过一定的进展后,我需要从Web服务器连接到客户端计算机以触发某些WMI功能。 一切正常,我可以连接其wmi并使用我的服务帐户(在客户端计算机上是管理员)触发操作

我的问题是我连接的WMI上下文始终是我的管理员帐户的上下文。 这不是我想要的,因为我需要以远程计算机上的当前登录用户身份运行它。

所以。 我需要使用我的管理员帐户登录到远程计算机,并以当前用户帐户身份运行功能。 可能吗 ? 或由于Windows的安全性而无法实现。

这就是我连接到远程计算机的方式

    ManagementScope wmiScope = new ManagementScope(@"\\" + remoteHost + wmiNameSpace);
wmiScope.Options.EnablePrivileges = true;
wmiScope.Options.Impersonation = ImpersonationLevel.Impersonate;
ManagementPath wmiClass = new ManagementPath(wmiClassName);
ManagementClass wmiObject = new ManagementClass(wmiScope, wmiClass, null);
return wmiObject;

这就是我触发功能的方式

  ManagementClass wmiConnection = clientConnection.ConnectRemoteWMI(remote, @"\ROOT\ccm\ClientSDK", "CCM_ClientUtilities");
            ManagementBaseObject parameters = wmiConnection.GetMethodParameters(policyType);
            ManagementBaseObject result = wmiConnection.InvokeMethod(policyType, parameters, null); 

这不是直接的答案。 但是,您应该在这里拥有所需的所有信息。

使用C#远程连接到WMI

简而言之,您将需要创建一个系统ManagementScope

注意 System.Management是用于访问WMI的原始.NET命名空间。 但是,此命名空间中的API相对于较现代的Microsoft.Management.Infrastructure相对而言通常较慢,并且扩展性也不太好。

然而

  1. 使用计算机的名称和WMI路径创建一个ManagementScope对象,并通过调用ManagementScope.Connect()连接到您的目标。

  2. 如果连接到其他域中的远程计算机或使用其他用户名和密码,则必须在对ManagementScope的调用中使用ConnectionOptions对象。

ConnectionOptions包含用于描述身份验证,模拟,用户名,密码和其他连接选项的属性。

ConnectionOptions options = new ConnectionOptions();
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;

// options takes more arguments, you need to read up on what you want

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

ManagementPath path = new ManagementPath("Win32_NetworkAdapterConfiguration");
ObjectGetOptions o = new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementClass objMC = new ManagementClass(scope, path, o);
...

一般来说,除非明确需要,否则建议您将模拟级别设置为“模拟”


补充阅读

使用C#远程连接到WMI

ManagementScope类别

ConnectionOptions类别

ObjectGetOptions类别

ManagementPath类别

管理类

免责声明 :您将必须阅读有关这些主题的信息,并弄清自己所处的情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM