我试图在使用WMI的远程服务器上执行程序。C#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 enabled'您可以远程调试..?如果没有,那么重构代码添加一些日志记录和一些错误陷阱..这不应该花你很长的时间来实现几行代码..还请联系远程服务器管理员,看看他们是否已经启用WMI可能是一个权限问题在你的本地机器外面工作.. – MethodMan