[英]C# WMI remote process execution
我正在尝试运行一个命令,在Win 2008框中调用批处理文件。 (登录Win 2008并单击时,命令成功运行)。
但是当我使用相同的用户凭据通过WMI调用此批处理文件时,批处理不会执行。
我的连接代码是:
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
connOptions.Username = UserName;
connOptions.Password = Password;
ManagementScope manScope = new ManagementScope(
String.Format(@"\\{0}\ROOT\CIMV2", ComputerName), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(
manScope, managementPath, objectGetOptions);
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = command;
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Object returnValue = outParams["ReturnValue"];
任何帮助表示赞赏......
在通过WMI在远程计算机上实例化命令时,需要指定显式凭据。 WMI增强了安全性,但这样做实际上降低了安全性,因为显式凭证以明文形式传递它们,而不像令牌。
如果将ROOT \\ CIMV2设置为服务器上脚本的默认命名空间,那么您应该只需要以下内容:
ManagementScope manScope = new ManagementScope(
String.Format(@"\\{0}", ComputerName), connOptions);
manScope.Connect();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.