I am trying to execute a program on a remote server using WMI.
When I execute my code, I can see the executable appear in the Process tab of Task Manager on the remote server, but it never actually performs its function. There should be some files in a specific folder when it runs correctly but there are none when I run it from my program.
Also, I check the result reported back from WMI and I get a code of 0, which I believe indicates there were no errors.
I have posted the code below. If something in my code is not obviously wrong then I would appreciate advice on how to troubleshoot this as I am new to the WMI process.
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();
}
}
}
I am answering this so I Can mark it as the answer for MethodMan. He was right, our server team says it is turned off.