我正在尝试使用WMI在远程服务器上执行程序。当我执行代码时,我可以看到可执行文件出现在远程服务器的任务管理器进程选项卡中,但它实际上从未执行其功能。当它正确运行时,特定文件应该存在于某个文件夹中,但是当我从我的程序中运行它时,这些文件并不存在。
此外,我检查了从WMI返回的结果,并得到了一个代码为0的结果,我相信这表示没有错误。
下面是我的代码。如果我的代码中没有明显错误,则希望获得有关如何排除故障的建议,因为我对WMI过程还不熟悉。
此外,我检查了从WMI返回的结果,并得到了一个代码为0的结果,我相信这表示没有错误。
下面是我的代码。如果我的代码中没有明显错误,则希望获得有关如何排除故障的建议,因为我对WMI过程还不熟悉。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using System.Management;
namespace ExecuteNetworkResources
{
class Program
{
static void Main(string[] args)
{
var processToRun = new[] { "C:\\Program Files\\TestApplication\\mscombine.exe -c -cwa" };
var connection = new ConnectionOptions();
connection.Username = "domain\\user1;
connection.Password = "password";
var wmiScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", "Server1"), connection);
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
object result = wmiProcess.InvokeMethod("Create", processToRun);
Console.WriteLine("Returned: " + result);
Console.ReadLine();
}
}
}
WMI
,您可以进行远程调试吗?如果没有,则重构代码以添加一些日志记录和错误捕获。这不应该花费太长时间来实现几行代码。此外,请联系远程服务器管理员并查看他们是否已启用WMI,可能是您本地机器之外的权限问题。 - MethodMan