I searched boards, Google and found a VB.Net sample that I converted to C#.
It uses WMI and returns success(0) with process ID, however batch file doesn't execute/code within batch file doesn't execute. Any ideas how to overcome this issue?
Thanks
========================================================
ConnectionOptions cOptions = new ConnectionOptions();
String workingDir = "D:\\FolderOnRemoteServer\\";
String mCommand = "cmd MyTestbatchFile.bat";
String servername = "\\\\NetworkServer\\";
ManagementScope scope = new ManagementScope(servername + "root\\cimv2", cOptions);
try
{
scope.Connect();
ManagementPath mp = new ManagementPath(servername + "root\\cimv2:Win32_Process");
ManagementClass mo = new ManagementClass(scope, mp, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 5), true));
ManagementBaseObject inParams = mo.GetMethodParameters("Create");
InvokeMethodOptions options = new InvokeMethodOptions();
inParams.SetPropertyValue("CommandLine", mCommand);
inParams.SetPropertyValue("CurrentDirectory",workingDir);
ManagementBaseObject mbo = mo.InvokeMethod("Create", inParams, options);
Object rv = mbo.GetPropertyValue("returnvalue");
Object prid = mbo.GetPropertyValue("processid");
}
catch (Exception e)
{
Console.WriteLine("Failed to connect: " + e.Message);
}
==========================================================