我正在尝试在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"];
非常感谢您的帮助...